i want to set strikethough in text when user click the checkbox inside the listView .Assume that i have three items inside the listView , but when i clicked the checkbox in first item , it only strikethough in text of last item .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView = (ListView) findViewById(R.id.productList);
model = helper.getAllProduct(list);
startManagingCursor(model);
listView.setAdapter(new ShoppingListAdapter(this,model));
class ShoppingListAdapter extends ResourceCursorAdapter {
public ShoppingListAdapter(Context context ,Cursor c) {
super(context,R.layout.productrow,c);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View row, Context context, Cursor c) {
// TODO Auto-generated method stub
listName = (TextView) row.findViewById(R.id.produtName);
final CheckBox listCheck=(CheckBox)row.findViewById(R.id.check);
listCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
// TODO Auto-generated method stub
if(listCheck.isChecked()){
listName.setPaintFlags(listName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
//listName.setTextColor(_context.getResources().getColor(R.color.red));
// listName.setText("go");
}
}
});
anybody know wat is my mistake ?
Lalit Poptani is correct it is because of recycling mechanism of listview. while scrolling the list , already created views will be reused. while scrolling getview() method will be called. so u have to check whether check box is checked or not. if it is checked u have to set paint flag and not means you have to remove the paint flags.