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

Relating Users in Parse.com CodeChallenge 1/2

Instructions : In this app we are managing a collection of websites for the user. The websites are stored in a ParseRelation. To remove a website when a user deletes it, we must first delete it from the relation in the app. Remove website from the variable mSitesRelation.

i dont understand what im doing wrong.... D:

here's the syntax:

import android.app.ListActivity;
import android.view.ListView;
import android.view.View;
import android.util.Log;
import com.parse.ParseUser;
import com.parse.ParseObject;
import com.parse.ParseRelation;
import com.parse.ParseException;
import com.parse.SaveCallback;

public class MainListActivity extends ListActivity {

    protected ParseUser mCurrentUser;
    protected ParseRelation<ParseObject> mSitesRelation;
    protected ParseObject[] mWebsites;

    protected SaveCallback mSaveCallback = new SaveCallback() {      
        @Override
        public void done(ParseException e) {
            if (e == null) {
               mSitesRelation.remove(website.get(position));
                Log.i("Website removed!");

            }
        }


    };

    /*
     * Some code has been omitted for brevity!
     */

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

        ParseObject website = mWebsites[position];

    }
}

Thanks for help :D

4 Answers

Hello,

This one confused me for a while. Here's what I did which worked.

public class MainListActivity extends ListActivity {

    protected ParseUser mCurrentUser;
    protected ParseRelation<ParseObject> mSitesRelation;
    protected ParseObject[] mWebsites;

    protected SaveCallback mSaveCallback = new SaveCallback() {      
        @Override
        public void done(ParseException e) {
            if (e == null) {

                Log.i("Website removed!");
            }
        }
    };

    /*
     * Some code has been omitted for brevity!
     */

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

        ParseObject website = mWebsites[position];

        //***Removing the website below.
        mSitesRelation.remove(website);
        //***

    }
}

Hope this helps, although I realize this forum thread is quite old.

Paul :)

I figured it has to be in onListItemClick method, but i still cant get it working.... i guess something is wrong whit codeChallenge engine or summthing. Or i am still doing somthing wrong but cant find out what. Please help me :D

That works for me

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

        ParseObject website = mWebsites[position];
        mSitesRelation.remove(website);

    }

mSitesRelation.remove(website);