I have a listview with custom BaseAdapter and each row contains a checkbox and three textviews. I am using Layoutinflater to inflate this row from a xml file. However, every
Use the OnClickListener instead of OnCheckedChangeListener. The latter is triggered even when you update the recycled view to match the value of the object. In the following piece of code of a getView() I'm using an HashMap to store the check value of the objects (itemMap).
boolean checked=itemMap.get(currentObject);
if(checked!=checkBox.isChecked())
checkBox.setChecked(checked);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox checkBox1=(CheckBox)v;
if(checkBox1.isChecked()) //ckecked
{
itemMap.put(currentObject,true);
if(checkListener!=null)
checkListener.onCheck(position,convertView,parent,adapter);
}
else{ //unchecked
itemMap.put(currentObject,false);
if(checkListener!=null)
checkListener.onUnCheck(position,convertView,parent,adapter);
}
}
});
checkListener is an additional listener that can be added by the user of the class.