why you changed id of checkbox
in your code?
holder.checked.setId(position);
if you want keep position in your checkbox
use Tag
instead of id
you can use:
holder.checked.setTag(position);
and for getting that:
int position = (Integer)holder.checked.getTag();
as you change id of checkbox in your code you get Resources$NotFoundException because you changed id of checkbox to 1,2,3,4,... and this not saved in R file,
// UPDATE
multiple select item happened because listviews-recycling, for solving this issue you need save selected position in one place or you can do:
add following property to PhoneList
boolean isSelected;
create getter and setter method for that.
public boolean getIsSelected()
{
return isSelected;
}
public void setIsSelected(boolean isSelected)
{
this.isSelected = isSelected;
}
then in your code in getView
method use:
holder.checked.setChecked(dta.getIsSelected());
and in click of checkbox change value of isSelected
to !isSelected
:
so your code must be like:
holder.checked.setOnClickListener(this);
in onClick
method:
data.get((Integer)v.getTag()).setIsSelected(!data.get((Integer)v.getTag()).getIsSelected);
notifyDataSetChanged();