lundi 25 avril 2016

ListView checkbox issue after check

My issue is that when I check Checkbox it turns to checked but it duplicates checked state for next ListView item which isn't on the visible list (e.g. when I can see item on positions 0-5/6 on one screen it is for element on position 7-8)...

This is my onClick method:

viewHolder.messageSelectBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (viewHolder.messageSelectBox.isChecked()) {
                    Log.i("itemID", String.valueOf(getItemId(position)));
                    Log.i("position", String.valueOf(position));
                    mListOfItemsToDelete.add(position);
                    Collections.sort(mListOfItemsToDelete);
                    Collections.reverse(mListOfItemsToDelete);
                } else {
                    for (int i = 0; i < mListOfItemsToDelete.size(); i++) {
                        int pos = mListOfItemsToDelete.get(i);
                        if (pos == position) {
                            mListOfItemsToDelete.remove(i);
                        }
                    }
                }
            }
        });

setOnClickListener is in getView() in ListView Adapter...

getView() method:

final ViewHolder viewHolder;

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater.inflate(R.layout.messages_list_view_single, parent, false);
        }

        viewHolder = new ViewHolder(convertView);

        viewHolder.messageSelectBox = (CheckBox) convertView.findViewById(R.id.messageSelectBox);

So guys, have you got any idea what is wrong?




Aucun commentaire:

Enregistrer un commentaire