I have a problem with ListView which recycles views that are visible on the screen.
I can have up to 4 items in my ListView, they are all visible on screen.
After I update a property of an object in the ArrayList that the ListAdapter uses i call the notifyDataSetChanged() method of the list adapter.
This causes the ListView to recycle the views and to redraw it self.
The problem is that it's doing the recycling in a reverse order. so if i have a button on the first Listview item it will be in the second list view item after the notifyDataSetChanged().
I have getView that changes the convertView properties except for the button onTouchListener.
This is very problematic if i have a button that works with touch event (Like PTT button). its visible for sometime and then it becomes invisible :-(.
1. why does the ListView recycle items that are visible on the screen ? is this normal behaviour? why does it do in reverse order ?
2. what can I do to solve my issue ?
Asked
Active
Viewed 970 times
3
-
1Could you please add some code from your adapter? – Dimitris Makris Aug 28 '11 at 11:06
-
1This is exactly the behaviour you should expect from list view framework, quoting an **Google Android Engineer Romain Guy** there is no guarantee how many times `getView()` will be called so you don't worry about that,also you need to ensure that your `Listview's` **height/width** should never be `wrap_content` for more details on how list view recycling mechanism works please refer http://stackoverflow.com/a/14108676/1939564 – Muhammad Babar May 07 '13 at 07:45
1 Answers
0
You should provide code for getview()
method. And adding button to an item could cause problems when you are not using checks on adding button.
Rather than adding button you should include button in all items and just make visible invisible the button at specific position where you want.
Also make check of "null" for creating convertview in getview()
method. This way it would not recycle/create views/item if they are not null.

Christian Specht
- 35,843
- 15
- 128
- 182

Rai
- 133
- 4
- 7