I have list view with custom row layout (list_row.xml) that contains CheckBox element:
What I have found is that because getView is redrawing and recycling the list item on scroll one needs to state explicitly when the check box should be checked and when not (similar solution for the selected item's background colour) in a statment like
if (condition){...set check box checked code...}else{...set check box unchecked code...}
The checkbox state can be derived from an array which must be updated every time the user check or uncheck the box in the list view.
I'm not sure I followed everything you said there, but keep in mind that ListView
recycles views as you scroll. This means that you cannot assume that a view will be in any default state at the start of getView
. This is probably why it doesn't work when you stop resetting the checkbox to the correct state every time you get a new view.
That said, did you consider using ListView
s built in checkbox tool? Set its choice mode to CHOICE_MODE_MULTIPLE and use one of their provided layouts, like android.R.layout.simple_list_item_multiple_choice
.