我知道您可以执行以下操作...
query.orderByAscending("rowValue");
query.orderByDescending("rowValue");
但是,如果您确实希望每次打开活动时数据都以随机顺序出现,该怎么办?怎么可以实现呢?
答案 0 :(得分:1)
为什么不在查询后随机化数据?
答案 1 :(得分:1)
您可以在使用Collections.shuffle()
实施例
ParseQuery<ParseObject> query = ParseQuery.getQuery("MyClass");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
Collections.shuffle(objects);
objectsWereRetrievedSuccessfully(objects);
} else {
objectRetrievalFailed();
}
}
}
答案 2 :(得分:0)
我想这很容易......我希望其他人觉得这很有帮助!
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"SuggestedUser");
ob = query.find();
// Randomizes the order of the records in the query
Collections.shuffle(ob);
for (ParseObject author : ob) {
ParseFile image = (ParseFile) author.get("brandImage");
SuggestedUser map = new SuggestedUser();
map.setRank((String) author.get("author"));
map.setUsername((String) author.get("username"));
map.setFlag(image.getUrl());
map.setUserID((String) author.get("userId"));
worldpopulationlist.add(map);