3

in my "Friends" class I have an user who has "friends". I saved the friends as pointers in an array. ([{"__type":"Pointer","className":"_User","objectId":"OZ3AKEq8ni"},{"__type":"Pointer","className":"_User","objectId":"v7kUba1T6U"}])

The user column is also a pointer.

Now I want to receive all friends of the current user and put them into an array. I tried this code but it didn't work:

ParseQuery<ParseObject> query = ParseQuery.getQuery("Friends");
query.whereEqualTo("user", ParseUser.getCurrentUser());
query.include("friends");

query.findInBackground(new FindCallback<ParseObject>() {
 public void done(final List<ParseObject> userList, ParseException e) {

  if (e == null) {

  }
  else {

  }
 }
});

At least I would like to have a list of usernames. Does anyone know how it is possible to do this?

1 Answer 1

3

Since you're querying for one user with their list of friends, your done() method should look like this:

public void done(final List<ParseObject> userList, ParseException e){
    if (e == null){
        if (userList != null && userList.size() > 0){
            ParseObject user = userList.get(0);  // only one match expected
            // now get the user's friends
            List<ParseObject> friends = user.getList("friends");
        }
    } else{

    }     
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.