Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kevin Nguyen
77 PointsI am trying to display items in friends detail extra credit activity Ribbt.
I am trying to get the ID of the user that was tapped on. I don't know how to communicate in my friends detail activity to state that I want to get the person's friends that was tapped on to display in a list view of the person's friends. If I were to tap on my friends name in friends list I want to see who they are friends with as well. This is my code so far...The error is on this line:
mFriendsRelations = mTappedOnUser.getRelation(ParseConstants.KEY_Friends_Relations);
package com.thegreathoudini.kevin.grapevine;
import android.app.AlertDialog; import android.app.ListActivity; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView;
import com.parse.FindCallback; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseQuery; import com.parse.ParseRelation; import com.parse.ParseUser;
import java.util.List;
public class FriendsDetailsActivity extends ListActivity {
public static final String TAG = FriendsDetailsActivity.class.getSimpleName();
protected TextView mUsernameDetails;
protected TextView mEmailDetails;
protected String mID;
protected String mUsernameText;
protected String mEmailText;
protected ParseUser mTappedOnUser;
protected ParseRelation<ParseUser> mFriendsRelations;
protected List<ParseUser> mFriends;
@[Ben Jakuben](https://teamtreehouse.com/benjakuben) Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends_details);
getActionBar();
//set variables
mUsernameDetails = (TextView) findViewById(R.id.usernameDetails);
mID = getIntent().getStringExtra(ParseConstants.KEY_ID); //objectID of tapped on person
}
@Override
protected void onResume() {
super.onResume();
mID = getIntent().getStringExtra(ParseConstants.KEY_ID); //objectID of tapped on person
mTappedOnUser = ParseUser.getCurrentUser().getParseUser(mID);
mFriendsRelations = mTappedOnUser.getRelation(ParseConstants.KEY_Friends_Relations);
ParseQuery<ParseUser> query = mFriendsRelations.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> detailUserFriends, ParseException e) {
if (e == null) {
//success
mFriends = detailUserFriends;
String[] detailUsernames = new String[mFriends.size()];
int i = 0;
for (ParseUser detailList : mFriends) {
detailUsernames[i] = detailList.getUsername();
i++;
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(FriendsDetailsActivity.this, android.R.layout.simple_list_item_1, detailUsernames);
setListAdapter(adapter);
}
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_friends_details, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Kevin Nguyen
77 Points1 Answer
Kevin Nguyen
77 PointsWow...I figured it out all on my own. =)
Kevin Nguyen
77 PointsKevin Nguyen
77 PointsHarry James