0

I have a listView created using DragSortListView library. I am able to check and unckeck rows created using a custom base adapter. I get the checked positions using getCheckedItemPositions() in my fragment code.

The issue is when I delete a particular row which is checked and add a new row then that new row is automatically checked. I want that row to get unchecked when it is deleted.

Here is what I have done inside getView() but it's not working.

holder.clearItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            items.remove(position);
            updateNoteAdapter(items);
            holder.container.setChecked(false); //row needs to be unchecked
        }
    });

items is the arraylist of items displayed in the list row.

holder.container is OneLineCheckableListItem class implementing Checkable.

public class OneLineCheckableListItem extends RelativeLayout implements Checkable{

public OneLineCheckableListItem(Context context, AttributeSet attrs){
    super(context, attrs);
}

private boolean checked;

@Override
public void setChecked(boolean checked) {
    this.checked = checked;

    ImageView iv = (ImageView) findViewById(R.id.SelectImageView);
    iv.setImageResource(checked ? R.drawable.ic_toggle_check_box : R.drawable.ic_toggle_check_box_outline_blank);

}

@Override
public boolean isChecked() {
    return checked;
}

@Override
public void toggle() {
    this.checked = !this.checked;
}

}

Is there anything I missed here? Any help is appreciated. Thanks.

Community
  • 1
  • 1
prasanjitDe
  • 179
  • 1
  • 7

1 Answers1

0

I found this solution below.

setChecked() doesn't check items, we have to use setItemChecked() on the ListView.

To check items in the CHOICE_MODE_MULTIPLE, you do not call setChecked() on the CheckedTextView. Call setItemChecked() on the ListView.

https://groups.google.com/forum/#!searchin/android-developers/choice_mode_multiple$20listview$20/android-developers/qPgt23C2-0o/Xdjs9ARPLGcJ

and this

Call Activity method from adapter

Community
  • 1
  • 1
prasanjitDe
  • 179
  • 1
  • 7