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 Build a Self-Destructing Message Android App Relating Users in Parse.com Adding Checkmarks When the List is Loaded

Joshua Silva
Joshua Silva
6,525 Points

(Android) App runs but Friends aren't being checked. Also, was code changed from the previous video and not in this one?

Hi, after completing the project I realized I stumbled upon the same error myself. My code looks very much similar to video's but it still isn't working for me, also I realized something about this video and the last video. In the last video, "Storing Friend Relationships" the onListItemClick method has code for adding and removing a friend, i know this because a comment is marked in the EditFriendsActivity.java class with //remove friend and //add friend, however in this video the code looks to be placed in separate positions without any instruction on how to move the code from //add friend to //remove friend. It threw me off so I went ahead and copied it as it is in this video, perhaps that may be the reason why it's not working for me. Anyhow, if you can please look at these lines of code for me that'd be great. I have the code from the "Storing Friend Relationships" onListItemClick method before it was modified and what it looks like now in this video.Thanks!


"Storing Friend Relationships" Video onListItemClick method :

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

        if (getListView().isItemChecked(position)){
            //add  friend
            mFriendRelation.add(mUsers.get(position));
            mCurrentUser.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e != null){
                        Log.e(TAG,e.getMessage());
                    }
                }
            });
        }
        else {
            //remove friend
        }
    }

Now here is the code for the "Adding Checkmarks" Video, both the onListItemClick and addFriendCheckmarks (Methods). Notice how in this example the //comments look different.

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

        if (getListView().isItemChecked(position)){
            //remove the friend
        }
        else {
            //add the friend
            mFriendRelation.add(mUsers.get(position));
            mCurrentUser.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e!= null){
                        Log.e(TAG,e.getMessage());
                    }
                }
            });
        }
    }

    private void addFriendCheckmarks(){
        mFriendRelation.getQuery().findInBackground(new FindCallback<ParseUser>(){
            @Override
            public void done(List<ParseUser> friends, ParseException e) {
                if (e == null){
                    //list returned - look for a match
                    for (int i = 0; i < mUsers.size(); i++) {
                        ParseUser user = mUsers.get(i);

                        for (ParseUser friend : friends) {
                            if (friend.getObjectId().equals(user.getObjectId())){
                                getListView().setItemChecked(i,true);
                            }
                        }
                    }
                }
                else{
                    Log.e(TAG,e.getMessage());
                }
            }
        });
    }
}

Joshua Silva
Joshua Silva
6,525 Points

Jon Kussmann Thanks for responding to my other post, sorry for going about it without the markdown sheet. Here is what I am asking!^^^

1 Answer

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Joshua,

I "skimmed" back through the videos... and you are right! The code does seem to move without any mention. Go ahead and follow the rest of the videos. The code that moved will be "back" to its original spot in the second to last part (you're almost there). Ben will then show you how to properly remove a friend.

I bet it's pretty confusing, but I would say that you are definitely paying attention to have caught something like that. If you still have questions, please let me know.