Android - Unable to check all the CheckBoxes in a custom listview because of recycling issue?

前端 未结 2 1580
醉梦人生
醉梦人生 2021-01-22 12:36

I have a custom listview adapter with a imageview, textview and a checkbox. and i also have a button and a checkbox in my main layout(not in listview).

What here i want

相关标签:
2条回答
  • 2021-01-22 12:44

    Yeah, this recycling is a pain.

    Here's what I did: http://dev.kafol.net/2011/11/android-checkbox-listview-un-check-all.html

    I'm still having some issues with SharedPreferences, as allthough I have managed to get all the checkboxes checked or unchecked, it still doesn't save the state to sharedpreferences.

    0 讨论(0)
  • 2021-01-22 13:03

    This morning I read an answer of an issue like this, and they recommend we put holder.checkBox.setChecked(itemChecked.get(position)); before holder.checkBox.setOnCheckedChangeListener

    So, getView function will be rewritten like this:

    public View getView(....)
    {
        ...
        holder.checkBox.setChecked(itemChecked.get(position));///move to here
        holder.checkBox.setOnCheckedChangeListener(...);
        ...
    )
    
    0 讨论(0)
提交回复
热议问题