Android ListView with Checkbox: automatically unchecks

后端 未结 2 1588
再見小時候
再見小時候 2021-01-02 22:01

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.setOnCheckedChang

相关标签:
2条回答
  • 2021-01-02 22:30

    Apparently the problem was that, by getting the checkbox using convertView.findViewById(), the onCheckedChangeListeners were still intact if the view was recycled. Calling checkbox.setOnCheckedChangeListener(null) did the trick.

    0 讨论(0)
  • 2021-01-02 22:34

    Use a boolean array to store the checked state of each list item, record the changes inside setOnCheckedChangeListener(), then call setChecked() after setOnCheckedChangeListener().

    0 讨论(0)
提交回复
热议问题