ListView Viewholder checkbox state

Here’s how I made it work:

First, you need a separate array for your checked state. It has to be the same size as your adapter’s getCount().

Then on your getView, your checkbox’s setOnCheckedChangedListener MUST PRECEED your checkbox.setChecked statements.

example:

holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  @Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    isChecked[position] = isChecked;
  }
});

holder.checkBox.setChecked(isChecked[position]);

Leave a Comment

tech