I have a problem with listview which list item contain a checkbox. When i check a box and scroll list, checkbox sometime auto call oncheckedchange and value of checkbox is c
holder.cBox.setOnCheckedChangeListener(null);
holder.cBox.setChecked(list.get(position).isChecked());
holder.tvName.setText(item.getName());
holder.cBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
list.get(position).setChecked(true);
}
else
{
list.get(position).setChecked(false);
}
}
});
In the list, the item have an attribute to set whether the item is checked or not. You can use this to set you item whether checked, and first you should set the
cBox.setOnCheckedChangeListener(null);
cBox.setChecked(list.get(position).isChecked());
Then set the real new OnCheckedChangeListener()
I hope my answer is useful for you and those who look at this page or have trouble dealing with listviews that have item checkboxes.