Reputation: 53
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());
}
Upvotes: 2
Views: 674
Reputation: 2011
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!
Upvotes: 0
Reputation: 1594
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
Upvotes: 1