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

Android

Passing parse data from list item click to new activity?

here is my code for when you click on some one in the friends list. ProfileActivity.class is essentialy just a blank list view right now. I need to know how to get the new activity to remember the list item that was clicked and then pull all the info on that user from parse and display in new activity. if that makes sense.. thanks!

    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        Intent intent = new Intent(getActivity(), ProfileActivity.class);

        startActivity(intent);
        };
    ```

2 Answers

Hello John,

I was stuck on the same extra credit. Here is how I made it work:

  1. created a ParseUser member variable and called it mUserClicked. (in the FriendListFragment activity)

  2. then on the onListItemClick listener method I made the variable equal to mFriendList.get(position); This stores the int position into that parse user.

3.you can then use that mUserClicked in the userProfile:

Hope this helps, let me know if you need further explanation. All the best, Ed.

Here is what it looks like :

public static ParseUser mUserClicked;

//some code (onCreate, onResume etc...)

 @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);


        mUserClicked = mFriendList.get(position);
        Intent intent = new Intent (getListView().getContext(),UserProfile.class);
        startActivity(intent);
    }
}

--

public class UserProfile extends Activity {

    protected ParseUser mUser;

    protected TextView mFirstNameHeader;
    protected TextView mLastNameHeader;
    protected TextView mHometownHeader;
    protected TextView mAboutMeHeader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_profile);

        mFirstNameHeader = (TextView) findViewById(R.id.first_name_header_profile);
        mLastNameHeader = (TextView) findViewById(R.id.last_name_header_profile);
        mHometownHeader = (TextView) findViewById(R.id.hometown_header_profile);
        mAboutMeHeader = (TextView) findViewById(R.id.aboutMe_header_profile);

        updateProfile ();
    }

    private void updateProfile() {
       mUser = FriendsListFragment.mUserClicked;
       mFirstNameHeader.setText( mFirstNameHeader.getText().toString().concat(mUser.get(ParseConstants.KEY_FIRSTNAME).toString()));
       mLastNameHeader.setText( mLastNameHeader.getText().toString().concat(mUser.get(ParseConstants.KEY_LASTNAME).toString()));
       mHometownHeader.setText( mHometownHeader.getText().toString().concat(mUser.get(ParseConstants.KEY_HOMETOWN).toString()));
       mAboutMeHeader.setText( mAboutMeHeader.getText().toString().concat(mUser.get(ParseConstants.KEY_ABOUTME).toString()));
    }

}

Thank you so much!! worked perfectly =]