I want to fill in ListViewwith the help of Arrayor ArrayListother ParseRolecurrent one associated with it ParseUser. I suppose this requires some kind of query for the current user, however I'm just not sure how you return the roles and also return them to Arrayor ArrayListwith which I could fill in ListView, I know that you can use the current user:
ParseUser.getCurrentUser();
However, I cannot find from there how you install the roles that have been allocated by the User.
EDIT:
I also tried experimenting with this:
ParseQuery<ParseRole> query = ParseRole.getQuery();
query.whereEqualTo("users", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback<ParseRole>() {
@Override
public void done(List<ParseRole> objects, ParseException e) {
if(e == null) {
Toast.makeText(getApplicationContext(), objects.size() + "", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).show();
}
}
});
. , , , "" - 0.
!
:
, , Waldal Android, , . , - :
ParseQuery<ParseRole> roleQuery = ParseRole.getQuery();
List<ParseRole> allRoles = null;
try {
allRoles = roleQuery.find();
} catch (ParseException e) {
e.printStackTrace();
}
userRoles = new ArrayList<ParseRole>();
userRolesNames = new ArrayList<String>();
for(ParseRole role : allRoles) {
ParseQuery usersQuery = role.getRelation("users").getQuery();
usersQuery.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
try {
if(usersQuery.count() > 0) {
userRoles.add(role);
userRolesNames.add(role.getName().toString());
}
} catch (ParseException e) {
e.printStackTrace();
}
}
GroupAdapter adapter = new GroupAdapter(this, userRolesNames);
workspaces.setAdapter(adapter);