0

I want to retrieve objects from parse that will be turned into an array. the Strings in the array will then go to a listview of dialog. I have been having problem getting the objects. Please help me out here.

Thank you very much.

This is the updated code:

    AlertDialog.Builder builderSingle = new AlertDialog.Builder(
                    AddSocialActivity.this);
            //builderSingle.setIcon(R.drawable.ic_launcher);
            builderSingle.setTitle("Select One Name:-");

            ParseUser currentUser = ParseUser.getCurrentUser();

            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MyProfile");
            final String currentUserUsername = currentUser.getUsername();
            final ArrayList<String> myProfile = new ArrayList<String>();
            //query.whereContainsAll(currentUserUsername, myProfile);
            query.whereEqualTo("user", currentUserUsername);
            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                    AddSocialActivity.this,
                    R.layout.select_dialog_singleitem, myProfile);

            //String profileName = ParseObject.getString("profileName");
            query.getFirstInBackground(new GetCallback<ParseObject>() {
                public void done(ParseObject object, ParseException e) {
                    if (object == null) {
                        //Log.d("score", "The getFirst request failed.");
                    } else {

                        arrayAdapter.add(object.getString("profileName"));
                    }
                }
            });
stanley santoso
  • 343
  • 1
  • 6
  • 19

1 Answers1

1

You only constrained the query in your code. To retrieve the query, add the following after the whereContainsAll method.

query.getFirstInBackground(new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (object == null) {
      Log.d("score", "The getFirst request failed.");
    } else {
      arrayAdapter.add(object.getString("profilName"));
    }
  }
});

Or, if you need to retrieve multiple objects, use the following.

query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> profileList, ParseException e) {
        if (e == null) {
            // manipulate list
        } else {
            Log.d("profile", "Error: " + e.getMessage());
        }
    }
});

Also, please check if your object key is "profilName" or "profileName".

edit: A for loop you can use.

for(ParseObject object : profileList) {
    arrayAdapter.add(object.getString("profileName"));
}
user4989692
  • 1,609
  • 1
  • 20
  • 25
  • Thank you very much for the answer. I tried the first one. the good news, it doesn't crash like it used to do. The bad news, there is no objects getting pulled. there is nothing shown in the dialog list. I already made sure of the object key. – stanley santoso Jul 25 '15 at 14:40
  • After a few iteration to my code, I managed to make it work halfway. I get the String I want. but, I only get 1 of them. I will need a couple of them depending on how many the user would have. How can I achieve that? – stanley santoso Jul 25 '15 at 14:47
  • @stanleysantoso, if you need to get one or more profiles use the `findInBackground` method I listed instead of the `getFirstInBackground` method. It will return a list of one or more profiles. You can then use a for loop to iterate the list and add all of them to your arrayadapter. – user4989692 Jul 26 '15 at 14:06
  • Owh. I see. Can you give me the sample code with the for loop? This will be my first time using for loop. – stanley santoso Jul 26 '15 at 22:14
  • http://stackoverflow.com/questions/18410035/ways-to-iterate-over-a-list-in-java - This shows various methods to write a for loop, I amended my answer to include one of them. – user4989692 Jul 27 '15 at 01:17
  • Also, when you have a new question, you probably should look up the answer or post it as a question on SO rather than tacking it onto your previous question. – user4989692 Jul 27 '15 at 01:24
  • @user4989693 I have been able to get the Strings into an array to display into the dialog. Thank you very much for that. I am wondering if I can also get images/icons from parse to show in the dialog as well. – stanley santoso Aug 05 '15 at 06:17