Hello I've created a custom adapter to my ListView in each row I have textEdit end check box I want when chceck box is clicked that text edit is strike thru and when unclicked the text view is normal.I've added a listener to checkbox but it strike thru only the last row even I click checkbox in first row the last will be change, I don't have any idea why. Here is my code
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int itemPos = (int) buttonView.getTag();
Product element = data.get(itemPos);
element.setSelected(isChecked);
if (data.get(position).isSelected()){
holder.txtName.setPaintFlags(holder.txtName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}else{
holder.txtName.setPaintFlags(holder.txtName.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
notifyDataSetChanged();
}
});
row.setTag(holder);
holder.checkBox.setTag(position);
}
else
{
holder = (RowHolder) row.getTag();
((RowHolder) row.getTag()).checkBox.setTag(position);
}
Aucun commentaire:
Enregistrer un commentaire