I am creating an app in android that allows the user to search other users registered in the app.
Each user is asked to enter a set of details like "Date of Birth" before entering into the app.These data are directly stored in the user class.
My requirement is that if a user enters a username and searches he must be able to see all the details available on that particular user. For eg.:Lets assume every user must have a email(String) and date of birth(String).An User searches for name "John". What should the query be so that I can retrieve both email and DOB of a user with username "John".
The data given in the Parse.com guide is
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", name);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(),"Query Success",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),"Query Not Successful",Toast.LENGTH_LONG).show();
}
}
});
What are the changes that I need to make so that I can achieve my goal?
How to access the string stored inside the object?
If I retrieve multiple records from my query how can I handle it?
I have edited my query like this
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereMatches("username", name);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
for(ParseUser singleobject:objects){
String mail=singleobject.get("email").toString();
Toast.makeText(getApplicationContext(),mail,Toast.LENGTH_LONG).show();}
} else {
Toast.makeText(getApplicationContext(),"Query Not Successful",Toast.LENGTH_LONG).show();
}
}
});
No toast is generated but the query is executed without any exception.
Is the looping statement correct or am i doing something wrong??
- What are the changes that I need to make so that I can achieve my goal?
The code looks like it correctly queries ParseUser for an exact match of a username. To match more loosely, consider using whereMatches
- How to access the string stored inside the object?
Parse.Object
provides getString()
as well as other "get" variations depending on the attribute type.
- If I retrieve multiple records from my query how can I handle it?
The "objects" parameter of the findInBackground
completion handler is an array that contains zero or more matches to the query. Handle this array the way you would any other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With