Usman Khan
Usman Khan

Reputation: 3953

Data getting from table using parse.com android

enter image description here

I am working on parse.com android application in which I want to get data from UserInfo table, Getting data from _User table is quite easy through .GetCurrentUser but I can't get data from UserInfo table like ObjectId etc columns. Some code snippet of mine is given below in which I want to get the data from UserInfo table. Attached snapshot is also given below for better understanding of a table.

 ParseQuery<ParseObject> query = ParseQuery.getQuery("UserInfo");
            // query.whereEqualTo("userName",user_name);
           query.findInBackground(new FindCallback<ParseObject>() {
               @Override
               public void done(List<ParseObject> categoryAttributes, ParseException e) {
                    if (e == null) {
                     for (int i = 0; i < categoryAttributes.size(); i++){

                     }
                       }
                    else {
                           Log.d("score", "Error: " + e.getMessage());
                          // Alert.alertOneBtn(getActivity(),"Something went wrong!");
                       }   
               }
           });

Upvotes: 1

Views: 438

Answers (1)

Owen Calzadilla
Owen Calzadilla

Reputation: 86

I make use of the query.find() but you would hove to create an AsyncTask. The way to do it with the query.findInBackground() would be the next:

//String id = "AnyID";
ParseQuery<ParseObject> query = ParseQuery.getQuery("UserInfo");
        // query.whereEqualTo("objectId", id);
        query.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> categoryAttributes, ParseException e) {
                if (e == null) {
                    for (ParseObject ob: categoryAttributes){
                        Log.d("DATA", "ObjectID: " + ob.getObjectId());
                        Log.d("DATA", "Column1: " + ob.getString("NameColumn"));
                        Log.d("DATA", "Column2: " + ob.getString("NameColumn"));
                        Log.d("DATA", "Column3: " + ob.getString("NameColumn"));
                    }
                }
                else {
                    Log.d("DATA", "Error: " + e.getMessage());
                    // Alert.alertOneBtn(getActivity(),"Something went wrong!");
                }
            }
        });

I couldn't she the name of the other tables but this would be the way to get the data out of a table of parse.Also you con see commented a way to look in a table for an object by its id.

String id = "AnyID";
ParseQuery<ParseObject> query = ParseQuery.getQuery("UserInfo");
         query.whereEqualTo("objectId", id);

Hope it was what you were looking for.

Upvotes: 1

Related Questions