【问题标题】:Parse.com - Android - searching for 3 objects in large object listParse.com - Android - 在大对象列表中搜索 3 个对象
【发布时间】:2015-06-25 21:20:27
【问题描述】:

我正在使用 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

【问题讨论】:

  • 能否在 findcallback 的 done 方法中添加日志消息,并检查您的查询是否检索到您需要的数据?
  • 您能否具体提供您的要求而不提供所有细节,因为我对您的实际要求有点困惑。
  • @55597 我添加了 log.w msgs 并且日志确实显示它们。我在 onCreate 方法中调用该方法(在我调用了所有其他方法之后(因此定义了需要预先定义的每个变量))。我已经查看了自己的代码,一切看起来都已经到位。谢谢回复。知道 Parse.com 的人并不多。
  • Here is my problem. How can I scan an entire Parse.com class and pull 3 objects out of it?Here is my Parse.com class:Click Here@RasikaSugathadasa

标签: java android database parse-platform


【解决方案1】:

如果您只想获得接下来即将到来的三场比赛,那么您应该这样做。根据您的喜好更改 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();
     }
   }
 });

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2015-11-05
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多