ListView Viewholder checkbox state

前端 未结 3 501
无人及你
无人及你 2020-11-29 10:25

I\'ve some problems with my ListView custom adapter (and its newly implemented viewHolder). I have a ListView with a checkbox for each item (nothing new here). The problem i

3条回答
  •  借酒劲吻你
    2020-11-29 11:17

    You should set CheckedBox state outside the initialization of ViewHolder, like the following code:

    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    
    viewHolder.checkedBox.setChecked();
    

    BTW: use SparseBooleanArray instead of two list to store CheckedBox state.

提交回复
热议问题