Skip to content Skip to sidebar Skip to footer

Android - Any Change Made To Any Of The Listview Item Is Affected To The First Item

I have a ListView which displays a list of items. When I click on an item, I mark the item as striked in my database table. Then, I update the list using a SimpleCursorAdapter, set

Solution 1:

I think it's because views are reused in ListView. Try to reset paint flags when view is not striked:

if(Integer.parseInt(cursor.getString(3)) == 1){
     textViewItem.setPaintFlags(textViewItem.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
 } else {
     //resed paint flags
     textViewItem.setPaintFlags(textViewItem.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
 }

Edit: I am not sure if my explatation is corect. When You have 10 items on ListView and only 5 of them are visible android creates(inflantes) only 5 views. When you scroll list one new item will be visible but olso one will disapear so there will be one unused view. Android wil take that unused view, fill it with new data and use it for newly appeared item. I found some more info here.

Solution 2:

you need different types of rows in your list(two types, striked and non striked), here is the best explaination i found for myself

https://stackoverflow.com/a/4778062/579646

Post a Comment for "Android - Any Change Made To Any Of The Listview Item Is Affected To The First Item"