Issue with ViewHolder selection

依然范特西╮ 提交于 2019-12-02 14:12:24

I checked what I did when I faced similar issue. I actually set the OnCheckedChangeListener only once (when the row was created i.e as inflater.inflate()). And I set the row number as tag to the CheckBox.

Following is my code:

if (convertView == null || convertView.getTag() == null) {
    holder = new Holder();
    //TODO set holder fields here
    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            int rowPosition = (Integer)buttonView.getTag();
            getItem(rowPosition).setMarked(buttonView.isChecked());
        }
    });
    convertView.setTag(holder);
}
else
    holder = (Holder) convertView.getTag();
holder.checkBox.setTag(position);
holder.checkBox.setChecked(item.isChecked());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!