我正在使用Parse.com数据库系统。在我的Android应用程序中,用户选择他们是谁(所有数据都已加载到数据库中)。用户已保存并记住。
该申请是我教会主办的本地排球比赛。我有一项活动向他们展示了即将到来的3场比赛。
这是我的问题。如何扫描整个Parse.com类并从中拉出3个对象?
这是我的Parse.com课程(这只是一些假队伍,所以我可以测试应用程序(事件是在10个月内)。)
链接:http://i.gyazo.com/c86a2a2f50a4bfdd8762e689c1b77585.png
(我无法直接拍照(我需要10个代表))。
以下是我的代码变量:
//Variable Members
String usernameString;
String ageString;
String ageGroupGames;
String game1;
String game2;
String game3;
int ageGroupInt;
int team;
int i = 0;
int i2;
int i3;
int MethodGameLog = 0;
int simpleID1;
String teamNumber;
TextView username;
TextView sched1;
TextView sched2;
TextView sched3;
TextView gameL1;
TextView gameL2;
TextView gameL3;
String g1t1;
String g1t2;
String g2t1;
String g2t2;
String g3t1;
String g3t2;
g1t1
代表游戏1团队1,依此类推。所有变量都设置为它们应该是什么,以及所有but g1t1, g2t1, ect
。
这是我尝试过的代码:
public void singleGameData(int simpleID) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ageGroupGames);
simpleID1 = simpleID;
query.whereEqualTo("team1", simpleID);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
if(team == -3){
Toast.makeText(getApplicationContext(), "The toast has been burnt!", Toast.LENGTH_SHORT);
return;
}
for (i = i; i < list.size(); i++) {
if(MethodGameLog == 0){
g1t1 = list.get(i).getString("team1");
g1t2 = list.get(i).getString("team2");
} else if (MethodGameLog == 1){
g2t1 = list.get(i).getString("team1");
g2t2 = list.get(i).getString("team2");
} else if(MethodGameLog == 2){
g3t1 = list.get(i).getString("team1");
g3t2 = list.get(i).getString("team2");
} else {
Toast.makeText(getApplicationContext(), "The toast has been fried!", Toast.LENGTH_SHORT);
}
MethodGameLog++;
if(MethodGameLog < 2) {
for (i = 0; i < list.size(); i++) {
singleGameData(simpleID1);
}
}
}
} else { //if no game1 in team1 search
for (i = i; i < list.size(); i++) {
if(MethodGameLog == 0){
g1t1 = list.get(i).getString("team1");
g1t2 = list.get(i).getString("team2");
i2 = i;
} else if (MethodGameLog == 1){
g2t1 = list.get(i).getString("team1");
g2t2 = list.get(i).getString("team2");
} else if(MethodGameLog == 2){
g3t1 = list.get(i).getString("team1");
g3t2 = list.get(i).getString("team2");
}
MethodGameLog++;
if(MethodGameLog < 2){
for (i = 0; i < list.size(); i++) {
singleGameData(simpleID1);
}
}
}
}
}
});
}
运行方法时得到的结果:我没有收到任何错误,但我得到了:
g1t1 = null
g1t2 = null
ect........
我把它们放在一个字符串中:
String game1 = g1t1 + " vs " + g1t2
然后在屏幕上设置:
textview1.setText(game1);
但我在屏幕上看到的是:
null vs null
答案 0 :(得分:0)
如果你只是想接下来的三场比赛,你应该怎么做。根据您的偏好更改orderByAscending或descending。
ParseQuery<ParseObject> query = ParseQuery.getQuery("YOUR_CLASS_NAME");
query.orderByDescending("gameTime");
query.setLimit(3);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
// list object will contain only 3 objects.
} else {
//objectRetrievalFailed();
}
}
});
希望这会有所帮助