I'm trying to implement CheckBox
with OnClickListener
. The examples available are all on OncheckedchangeListener
.
Once I select one CheckBox
, and I scroll down the ListView
, random CheckBox
are getting checked. no idea why?
holder.checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox checkbox = (CheckBox) v;
ClaimList claimList = (ClaimList) checkbox.getTag();
claimList.setChecked(checkbox.isChecked());
}
You need to use ViewHolder
in ListView
Adapter
also need to add boolean
flag for selected item in getter setter Class
Check this link : Listview with Checkbox
I had the same problem. I solved it by overriding this two method in adapter class.
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.