user3289546
user3289546

Reputation: 11

Getting a ParseUser from a List<ParseUser> using Parse SDK for android?

Using the Parse SDK for android, I'm trying to receive a ParseUser from a query, the following code is what I have tried:

ParseQuery<ParseUser> query = ParseUser.getQuery();

Follow.include("author");
query.whereEqualTo("User", "Alex"); 
query.findInBackground(new FindCallback<ParseUser>() {       
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// This is where I want to receive the ParseUser from the List<ParseUser>
ParseUser pu = objects.get("author");
} else {

}


} });

Object.get("author") creates errors.

Thankyou for reading :)

Upvotes: 0

Views: 1486

Answers (1)

droidx
droidx

Reputation: 2172

ParseUser pu = objects.get("author"); would be incorrect usage. Get method is generally used to get a object at a particular position in the list.

The query returns a list of ParseUsers which you have named as objects. Now use an iterator to go through the list to access each ParseUser.

like this

for(ParseUser pu : objects){
       //access the data associated with the ParseUser using the get method
       //pu.getString("key") or pu.get("key") 
} 

Hope this helps!

Upvotes: 1

Related Questions