ListView Viewholder checkbox state

前端 未结 3 506
无人及你
无人及你 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:18

    The problem is because of the fact that listview recycles it views

    so in getView() method

         if (convertView == null)
            {
        ........
             }
        else 
            {
                holder = (ViewHolder) convertView.getTag();
    
    
            }
      // Uncheck needed boxes here... You need to implement your logic 
            if( 'position' is checked earlier)
             holder.check.setChecked(true);
            else
            holder.check.setChecked(false);
    

    You need to write the code to manage the state of view if the convert is not null, because it is a already used view which may be having checked check boxes.

提交回复
热议问题