0

我了解您可以执行以下操作...

query.orderByAscending("rowValue");
query.orderByDescending("rowValue");

但是,如果您真的希望您的数据在每次打开活动时以随机顺序出现怎么办?这怎么可能实现?

4

3 回答 3

1

Parse API中没有用于随机排序顺序的内置函数。

您可以在收到列表后使用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();
         }
     }
 }
于 2015-10-17T17:34:17.623 回答
1

Why not just randomize the data after you query?

于 2015-10-17T17:22:26.220 回答
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);
于 2015-10-17T17:48:30.823 回答