Android ListView with Checkbox: automatically unchecks

Posted by Kilnr on Stack Overflow See other posts from Stack Overflow or by Kilnr
Published on 2010-05-03T09:26:23Z Indexed on 2010/05/03 15:18 UTC
Read the original article Hit count: 1392

Filed under:
|
|
|

Hi,

I've got a ListView with a custom BaseAdapter. The list items contain CheckBoxes that need to represent a property from a database.

I use CheckBox.setOnCheckedChangeListener with a new OnCheckedChangeListener to detect changes, so I can change the database based on the current state of the CheckBox. Pretty straightforward stuff so far.

However, when scrolling further down the list, previously checked CheckBoxes get unchecked. I suspect this happens as soon as the views are recycled (I'm using the convertView/ViewHolder technique).

How can I stop this? What's going wrong?

Thanks in advance.


Edit: To make things a bit clearer, the problem is that recycling views somehow calls OnCheckedChangeListener#onCheckedChanged(buttonView, isChecked) with isChecked == false.

© Stack Overflow or respective owner

Related posts about android

Related posts about listview