how to limit checkbox selection in listview?

前端 未结 5 1259
暖寄归人
暖寄归人 2020-12-30 17:35

friends,

i want to limit checkbox selection in android listivew to for example only 3 checkboxes should be selected otherwise it should give error message.

u

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 18:12

    i solved the issue "after scroll listview user can also again select more than 3 check boxex" Thanks for you patience set static int count = 0;

                         if (isChecked) {
                            count++;
                        } else if (!isChecked) {
                            count--;
                        }
    
                        if (count >= 4) {
                            buttonView.setChecked(false);
                            count--;
                        } else {
                            int getPosition = (Integer) buttonView.getTag();
    
                           contact.get(getPosition).setSelected(buttonView.isChecked());
                        } 
    

    And Most imprtant is that add count=0 in else and viewHolder.chkContact.setTag(position) after else;

    if(convertView == null){   
    
    }else
    {
     viewHolder = (ViewHolder) convertView.getTag();
     count=0;
     }
     viewHolder.chkContact.setTag(position);
    

    `

提交回复
热议问题