我正在尝试获取从 ParseQueryAdapter 返回的对象数量,并将它们放在 TextView 中以向用户显示加载的数量。
我尝试过类似的操作,但即使项目已正常加载到 ListView 中,也一直显示 0。
bookSalesAdapter = new BookSalesAdapter(this);
setListAdapter(bookSalesAdapter);
int bookSalesAmount = bookSalesAdapter.getCount();
String bookSales = Integer.toString(bookSalesAmount);
TextView salesAmount = (TextView) findViewById(R.id.textView_bookSalesAmount);
salesAmount.setText(bookSales);
关于如何使用 ParseQueryAdapter 获取项目数量而不是运行另一个查询,有什么想法吗?
这似乎不适用于 ListView 的 Activity 。
最佳答案
尝试使用 ParseQueryAdapter.OnQueryLoadListener .
您可以编写代码在适配器加载对象后运行。从那里,您应该能够获取计数。
在调用 setListAdapter() 之前:
bookSalesAdapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<Book>() {
@Override
public void onLoading() {}
@Override
public void onLoaded(List<Event> events, Exception e) {
// Access the item count through the adapter's getCount() and update your UI...
}
});
关于android - 从 ParseQueryAdapter 返回项目数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22615121/