2

I am new to parse data from parse.com.I am trying to update a column.The column in parse table is of array type.I am trying to add a value in array.For Example :

it is showing in data browser like this:

["Ado", "Wassja", "Cristi_3"]

And I want to add "ABC" value in this array programmatically like this:

["Ado", "Wassja", "Cristi_3","ABC"]

I have searched for this and got to know that first I need to fetch all the data of that particular row which I have to update ,then put the data in array I have fetch successfully the data for that particular row like this:

ParseQuery<ParseObject> query = ParseQuery.getQuery("UserMaster");
    query.whereEqualTo("userName",str_uname2);
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> userList, ParseException e) {
            dlg.dismiss();

             if (e == null) {
                 if (userList.size()>0) {

                 for (int i = 0; i < userList.size(); i++) {
                     ParseObject p = userList.get(i);
                     str_dbpassword  = p.getString("password");
                     String email = p.getString("email");
                     List<ParseObject> mfollowers = p.getList("followers");
                     List<ParseObject> mfollowing =       p.getList("following");
                     ParseFile pp = (ParseFile)p.get("photo");

                     str_dbuname = p.getString("userName");

                 } 
                 Log.d("password", "Retrieved " +str_dbpassword +"<uname>"+str_dbuname);

                    }

                }
             else {

                    Alert.alertOneBtn(LoginActivity.this,"Something went wrong!");
                }   
        }
    });

Now I have to update data in

List<ParseObject> mfollowers = p.getList("followers"); 

And

List<ParseObject> mfollowing =  p.getList("following");

I don't know how to do this.Please help me.Your small clue will be very helpful.

2 Answers 2

4

Per the docs: http://parse.com/docs/android/api/com/parse/ParseObject.html

You can use add, addUnique, addAll, or addAllUnique to add elements to an array on a Parse Object:

someParseObject.add("arrayColumn", "ABC");
someParseObject.saveEventually();
1
  • Thanks for your response.I have tried this ,but it gives me the exception : IllegalArgument Exception You must create this type of ParseObject using ParseObject.create() or the proper subclass. Jun 25, 2014 at 9:15
2

To expand on Fosco's answer:

  ParseObject parseObject = new ParseObject("YOURCLASS");
  String[] stringArray = ["Ado", "Wassja", "Cristi_3"];
  List<String> stringArrayList = new ArrayList(Arrays.asList(stringArray));
  if (stringArray != null)parseObject.addAll("YOURCOLUMN", stringArrayList);

Make sure that the security settings for YOURCLASS enable you to create columns automatically or that you have the correct types set for your columns.

I hope that completes Fosco's answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.