3
votes

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

1 Answers

3
votes

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{

    }     
}