0

我从 parse.com 得到一个数组。我正在使用一个数组来检索一个数组:

 fightList.whereContainedIn("objectId", itemListCard);
 fightList.findInBackground(new FindCallback<ParseObject>() ....

我的第一个数组;itemListCard是按特定顺序的。在 I 之后findInBackground,我的在线数组 ( objectId) 完全出故障了。这是因为我是从 Parse.com 获取它的,所以它在检索时被添加到数组中。我需要:

1.重新排序数组objectId以匹配itemListCard

objectId2.按顺序检索itemListCard


Java代码:

HomeItemList = new ArrayList<HomeItem>();
    fightList.whereContainedIn("objectId", itemListCard);

    fightList.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objectId, ParseException e) {
            if (e == null) {

                for (int i = 0; i < objectId.size(); i = i + 2) {
                    HomeItem homeItem = new HomeItem();
                    homeItem.setHomeItemID(k);
                    k++;
                    //set Red Array
                    homeItem.setHomeItemRedName(objectId.get(i).getString("Name"));
                    homeItem.setHomeItemRedAge(objectId.get(i).getString("Age"));
                    homeItem.setHomeItemRedRecord(objectId.get(i).getString("Record"));
                    homeItem.setHomeItemRedHeight(objectId.get(i).getString("Height"));
                    homeItem.setHomeItemRedWeight(objectId.get(i).getString("Weight"));
                    homeItem.setHomeItemRedCity(objectId.get(i).getString("Location"));
                    homeItem.setHomeItemRedExp(objectId.get(i).getString("Experience"));

                    //set blue Array
                    homeItem.setHomeItemBlueName(objectId.get(i+1).getString("Name"));
                    homeItem.setHomeItemBlueAge(objectId.get(i+1).getString("Age"));
                    homeItem.setHomeItemBlueRecord(objectId.get(i+1).getString("Record"));
                    homeItem.setHomeItemBlueHeight(objectId.get(i+1).getString("Height"));
                    homeItem.setHomeItemBlueWeight(objectId.get(i+1).getString("Weight"));
                    homeItem.setHomeItemBlueCity(objectId.get(i+1).getString("Location"));
                    homeItem.setHomeItemBlueExp(objectId.get(i+1).getString("Experience"));

                    HomeItemList.add(homeItem);
                    }

                HomeListAdapter = new HomeListAdapter(getApplicationContext(), 0, HomeItemList);
                adapter.addSection(" Fight Card ", HomeListAdapter);

            } else {
                progressDialog.dismiss();
                Log.d("Display Card", "Error parsing Card");
                Log.d("Card Error:", e.getMessage());
                Toast.makeText(databaseFightCard.this, "Could not retrieve parse info. Try again later", Toast.LENGTH_LONG).show();
            }
            listView.setAdapter(adapter);
            progressDialog.dismiss();
        }
    });

笔记

for 循环按 2 计数,因为这是我要使用的结构:

 objectId[0] vs objectId[1]
 objectId[2] vs objectId[3]
 objectId[4] vs objectId[5]
 objectId[6] vs objectId[7]
 ....and so on

因此需要特定的顺序。

4

1 回答 1

0

您可以使用 orderByAscending() 和 orderByDescending() 控制返回项目的顺序。

在你的情况下:

fightList.whereContainedIn("objectId", itemListCard);
fightList.orderByAscending("objectId");
fightList.findInBackground(new FindCallback<ParseObject>() ....

请参阅Parse Android Guide 的查询约束部分

于 2013-10-23T00:17:27.987 回答