我正在尝试计算我的解析数据库中的用户数,并将其作为计数器传递给我的滑动菜单。但是,它总是返回null(我在解析用户db中有超过100个用户)。我在滑动菜单中的代码如下:
有什么想法吗?
countuser = 0;
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> users, ParseException e) {
if (e == null) {
// Success
mUsers = users;
countuser = mUsers.size();
}
}
});
我想将反对者传递给我的导航项目:
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons
.getResourceId(3, -1), true, "("+ countuser +")"));
答案 0 :(得分:3)
Android, Queries, Counting Objects下的文档中介绍了这一点。
ParseQuery<ParseUser> query = ParseUser.getQuery();
// set any filters...
query.countInBackground(new CountCallback() {
public void done(int count, ParseException e) {
if (e == null) {
// all good
countuser = count;
}
}
});
答案 1 :(得分:0)
万一有人来这里
在新的解析服务器中,您可以尝试以下操作:
-p, --preserve-merges
Recreate merge commits instead of flattening the history by replaying commits a
merge commit introduces. Merge conflict resolutions or manual amendments to merge
commits are not preserved.
This uses the --interactive machinery internally, but combining it with the
--interactive option explicitly is generally not a good idea unless you know what
you are doing (see BUGS below).
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.whereEqualTo("playerName", "Dan Stemkoski");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
返回计数