简体   繁体   中英

Parse.com - Android - searching for 3 objects in large object list

I am using Parse.com database system. In my Android application the user selects which person they are (all that data is already loaded into the database). The user is saved and remembers.

The application is a for a local Volleyball tournament my church hosts. I have an activity that shows them the next upcoming 3 games.

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 (this is just some fake teams slapped together so I can test the app (event is in 10 months)).

Link: http://i.gyazo.com/c86a2a2f50a4bfdd8762e689c1b77585.png

(I can't directly put the picture up (I need 10 rep)).

Here are my code Variables:

//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 stands for game 1 team 1, and so on. All the variables are setup to what they are supposed to be, well all but g1t1, g2t1, ect .

Here is my attempted code:

 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);
                        }
                    }
                }
            }
        }
    });
}

What I get when I run the method: I don't get any errors, but I get:

g1t1 = null
g1t2 = null
ect........

I am putting them into a single string:

 String game1 = g1t1 + " vs " + g1t2

and then set on screen:

textview1.setText(game1);

But what I see on screen is:

null vs null

If you just want to get next upcoming three games this is how you should do it. change orderByAscending or descending according to your preference.

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();
     }
   }
 });

hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM