Parse.com android view request result
I have a question, this may sound like a silly question, but I really don't know how to answer.
In parse.com, after the request completes, how can I display the result
For example this
ParseQuery<ParseObject> gameQuery = ParseQuery.getQuery("Game");
gameQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
I want to set the result of a query to a text view in my application
textview.setText(??)
:;
Thank you in advance:)
Edit:
and this is the code i am using
public class Adapter extends ParseQueryAdapter<ParseObject> {
//MediaPlayer mediaPlayer;
public Adapter(Context context) {
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Game");
return query;
}
});
}
// Customize the layout by overriding getItemView
@Override
public View getItemView(final ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.list_item, null);
}
super.getItemView(object, v, parent);
// I'm getting Images from Game class
ParseImageView audioImage = (ParseImageView) v.findViewById(R.id.list_image);
ParseFile imageFile = object.getParseFile("img");
if (imageFile != null) {
audioImage.setParseFile(imageFile);
audioImage.loadInBackground();
}//end if
//retrieving Titles from Game Class
TextView titleTextView = (TextView) v.findViewById(R.id.list_title);
titleTextView.setText(object.getString("title"));
//Now I want to retrieve name from User Class :(
// the code is crashing my app
//?????????????????????????????????????????????????
ParseQuery<ParseObject> userQuery = ParseQuery.getQuery("Game");
userQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
userQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, com.parse.ParseException e) {
if (e == null) {
ParseObject userName = list.get(0); // Gets first object
// You can get fields using the get() method
ParseUser user = (ParseUser) userName.get("createdBy");
// There are data specific methods as well
String firstName = user.getString("name");
nameTextView.setText(firstName);
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
return v;
}//end getItem View
}//end custom Adapator
source to share
ParseQuery<ParseObject> gameQuery = ParseQuery.getQuery("Game");
gameQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
gameQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> gameList, ParseException e) {
if (e == null) {
ParseObject game = gameList.get(0); // Gets first object
// You can get fields using the get() method
ParseUser user = game.get("createdBy");
// There are data specific methods as well
String firstName = user.getString("userFirstName");
textview.setText(firstName);
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Above is an example. See the documentation for ParseObject
all methods get*()
to get data from an object.
Some of them are: get()
, getString()
, getBoolean
, etc.
UPDATE:
First you will need to specify your query to fetch pointer data (Parse does not include pointer data for queries by default). This is why your application crashes. So update your query to this:
ParseQuery<ParseObject> userQuery = ParseQuery.getQuery("Game");
userQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
userQuery.include("createdBy");
UPDATE 2:
public class Adapter extends ParseQueryAdapter<ParseObject> {
//MediaPlayer mediaPlayer;
public Adapter(Context context) {
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Game");
userQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
query.include("createdBy");
return query;
}
});
}
// Customize the layout by overriding getItemView
@Override
public View getItemView(final ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.list_item, null);
}
super.getItemView(object, v, parent);
// I'm getting Images from Game class
ParseImageView audioImage = (ParseImageView) v.findViewById(R.id.list_image);
ParseFile imageFile = object.getParseFile("img");
if (imageFile != null) {
audioImage.setParseFile(imageFile);
audioImage.loadInBackground();
}//end if
//retrieving Titles from Game Class
TextView titleTextView = (TextView) v.findViewById(R.id.list_title);
titleTextView.setText(object.getString("title"));
//Now I want to retrieve name from User Class :(
// the code is crashing my app
//?????????????????????????????????????????????????
// You can get fields using the get() method
ParseUser user = (ParseUser) object.get("createdBy");
// There are data specific methods as well
String firstName = user.getString("name");
nameTextView.setText(firstName);
return v;
}//end getItem View
}//end custom Adapator
source to share