简体   繁体   中英

Android parse.com delete object from array

You can see what i am talking about in this picture

在此输入图像描述

I have an array called "statusLikers" under a class called "Status". I am trying to create a facebook/instagram like/unlike functionality on button click.

Now, before i move on from where i am, i am trying to figure out how to remove users from the array.

I know how to add to th array but i dont know how to delete from it.

The way i am going about it is like this

List<Object> likesPpl = status.getList("statusLikers");
JSONObject myObject = new JSONObject();

try {
    myObject.put("statusLikers", currUser.getUsername());
} catch (JSONException e1) {
    e1.printStackTrace();
}

likesPpl.removeAll(Arrays.asList(myObject));

but it does not seem to work, first i want to learn to remove items from the array before i create the if statements.

to remove data from an array of a Parse Tab

 List<String> ary_users = new ArrayList<String>();
ParseQuery<ParseObject> queryPart1 = ParseQuery.getQuery("Channel");
    queryPart1.whereEqualTo("objectId",channel_id);

    queryPart1.findInBackground(new FindCallback<ParseObject>() {

        @Override
        public void done(List<ParseObject> list, ParseException e) {
            if (e==null) {
                if (list.size()>0) {
                    ParseObject p = list.get(0);
                    if (p.getList("usersArray")!=null) {
                        ary_users =  p.getList("usersArray");
                    }
                    else
                    {
                        ary_users =  null;
                    }
                    if (ary_users!=null) {
                        if (ary_users.contains(frnd_objid)) {
                            ary_users.remove(frnd_objid);
                            p.put("usersArray",ary_users);
                            p.saveInBackground(new SaveCallback() {
                        @Override
                    public void done(ParseException arg0) {
            Toast.makeText(activity,frnd_name+ "is successfully removed in the channel"+channel_name,Toast.LENGTH_LONG).show();
                        }
                         });
                        }
                    }
                }
            }
        }
    });
    }

Here "usersArray" is an Array of table "Channel" .And I am removing "frnd_objid" from the "usersArray"

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