0

The problem is that each time I click on item it is replacing the item that was added early, so the first listview has only the last added item. Here is my code:

lvUsersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            pb.setVisibility(View.VISIBLE);
            final Contacts contact = (Contacts) adapter.getItem(position);
            final RequestParams params = new RequestParams();
            params.add("member", contact.getId());
            params.add("id", gcId);
            AsyncHttpClient asyncClient = new AsyncHttpClient();
            asyncClient.addHeader("User", userId);
            asyncClient.post("http://prev.gio.uz/addGroupChatMember", params, new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    pb.setVisibility(View.GONE);

                    String json = new String(responseBody);
                    try {
                        JSONObject object = new JSONObject(json);
                        JSONObject jsonObject = object.getJSONArray("data").getJSONObject(0);
                        Log.i("myLogs", "gc member added successfully");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    Toast.makeText(getApplicationContext(), "Group member added", Toast.LENGTH_SHORT).show();
                    List<AddedUsers> addedUsersList = new ArrayList<AddedUsers>();
                    AddedUsers au = new AddedUsers();
                    au.setId(contact.getId());
                    au.setFullName(contact.getFullName());
                    addedUsersList.add(au);

The code is ugly as ****, hope you understand, I'll explain more if needed

Yusuf
  • 145
  • 6
  • 12
  • every time when you click on item it will create new object of AddedUsers au = new AddedUsers(); so every time its a new list on every click – santoXme Dec 23 '15 at 05:27
  • 1
    @Yusuf Abdullaev: u r creating new addedUserList everytime u click on item in 2nd ListView. this line List addedUsersList = new ArrayList(); instead declare addedUsersList as class member and define it inside onCreate(). – kevz Dec 23 '15 at 05:28
  • Refresh your both adapters after added to another listView – Piyush Dec 23 '15 at 05:35
  • @kevz thanx mate it's working, I'm feeling stupid now :) – Yusuf Dec 23 '15 at 05:42
  • @Yusuf Abdullaev: Dude its okay. Keep calm n code :) – kevz Dec 23 '15 at 05:44

0 Answers0