When scrolling custom ListView, the checkbox value changes

前端 未结 8 1947
不思量自难忘°
不思量自难忘° 2020-12-05 07:30


What I have: a custom listview with Textviews and checkbox.


Problem: Suppose my screen can show only 6 items of list at time, and
8条回答
  •  再見小時候
    2020-12-05 08:05

    You need to update the adapter to retain the value of checkbox

    holder.chk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox c = (CheckBox)v.findViewById(R.id.chkID);
                    Boolean chk = c.isChecked();
                    Integer pos = (Integer)v.getTag();
                    itemList.get(pos).setChk(chk);
    
                }
            });
    

    For more help you can refer this post in Retain Checkbox value

提交回复
热议问题