I am developing a Android Chat Messaging App Using Parse where I am saving user's phone number, username and password during the sign up process that I have completed successfully. Now I want to fetch the list of users already saved under the Phone Contact list matching their phone numbers and display the users in a list view. I am stuck of writing the Parse query and showing the fetched users in a list view.
EDIT: I am trying to play around the following code, but clueless yet.
ParseUser user1 = ParseUser.getCurrentUser();
ParseQuery<ParseUser> parseQuery = user1.getQuery();
parseQuery.whereEqualTo("PhoneNumber", some_ph_no_from_my_contact);
parseQuery.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> numberList, ParseException e) {
// TODO Auto-generated method stub
if(e == null){
for (int i = 0; i < numberList.size(); i++)
{
// What to do here?
}
}
else{
Log.d("userId", "Error: " + e.getMessage());
}
}
});
Please help.
You can use a OR
query:
public void getFriends(List<String> numbers) {
List<ParseQuery<ParseUser>> queries = new ArrayList<ParseQuery<ParseUser>>();
for (String number : numbers) {
ParseQuery<ParseUser> parseQuery = ParseUser.getQuery();
parseQuery.whereEqualTo("PhoneNumber", number);
queries.add(parseQuery);
}
ParseQuery<ParseUser> userQuery = ParseQuery.or(queries);
userQuery.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> numberList, ParseException e) {
if (e == null) {
for (int i = 0; i < numberList.size(); i++) {
// What to do here?
//Use this list of ParseUser (numberList) in an ArrayAdapter
//or save it in a database
}
}
}
});
}
List<String> numbers
would be the list of phone numbers from the user's addressbook.
Once you have the List<ParseUser>
just feed it to an ArrayAdapter<ParseUser>
or save it in a local database, your choise (I'd go with the database).
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加