Android ListAdapter无法应用于Parse FindCallback

时间:2017-03-05 22:03:15

标签: android parse-platform callback

尝试将Parse查询的结果应用于列表适配器时出错。我想将Parse查询的结果分配给Android上的列表适配器。我无法在回调之外分配结果,因为查询是findInBackground,结果将不会及时返回。以下是我正在使用的代码:

private void setupList() {
    ListView listView = (ListView) findViewById(R.id.list_view);
    Log.i("Setup List", ParseUser.getCurrentUser().getObjectId());

    // Get the number of children the user has...
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Children");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> list, ParseException e) {
            if (e == null){
                Log.i("Find All", "Retrieved: " + list.size());
                if (list.size()>0){
                    numChildren = list.size();

                    adapter = new ListAdapter(this, createList(numChildren));
                    listView.setAdapter(adapter);
                }
                Log.i("Find All", "Success!");
            }
            else {
                Log.i("Find All", "Failed!");
            }
        }
    });

    //Log.i("About to call the list", "Retrieved");
    //adapter = new ListAdapter(this, createList(numChildren));
    //listView.setAdapter(adapter);
  }

1 个答案:

答案 0 :(得分:0)

尝试ParseQueryAdapter。这将在后台找到结果时自动填充您的列表。