arraylist - Parse.com - Android: boolean on if a User belongs to an Array -
i have array of users in class, under column "likers" want check whether or not current user contained in likers array, in minimal time current (dysfunctional) code:
arraylist<parseuser> likers = (arraylist<parseuser>) rating.get("likers"); boolean contained = likers.contains(parseuser.getcurrentuser()) //always returns false
how can change make work? feel it's match on objectid
. maybe there function in parse sdk?
thanks!
you can use next approach.
parseobject rating = parseobject.create(parseobject.class); arraylist<parseuser> likers = (arraylist<parseuser>) rating.get("likers"); boolean contained = containsuser(likers, parseuser.getcurrentuser());
method
private boolean containsuser(list<parseuser> list, parseuser user) { (parseuser parseuser : list) { if (parseuser.hassameid(user)) return true; } return false; }
little bit code. works correct, return false. because arraylist implements list interface. if @ javadoc list @ contains method see uses equals() method evaluate if 2 objects same. result of rating.get("likers") contains same parseusers parseuser.getcurrentuser, different objects @ memory. need find comparing objectid parse.com.
Comments
Post a Comment