Question

So I am having a problem with the different pieces of that make up my ListView. I put them into an ArrayList and use a custom ArrayAdapter to hook up to the ListView, which I have done before so I don't believe there is a problem there. Initially the list seems to have the pieces in the correct order, but then I will scroll down the list and the contents will then load in incorrect order. I then scroll back up and everything is jumbled. Has anyone run into this before?

Thanks -Jake

Was it helpful?

Solution

Yes your problem is related to the fact that List reuses the views for each row. So say your list can see 5 items, but your ListAdapter has 15 things in it. Android will create 5 + 1 instances of your row view instead of 15. One for each row in the list + 1 for when half of the top and bottom can be seen. When a row is moved out of the visible area the List will recycle that view instance for another row instead of creating a new one. If you don't properly reset all of the user interface components every time you'll get artifacts from other rows showing up. You must make sure that every time you bind your data from the objects in your array list to the view you set every field every time.

For a better description of this see

http://www.youtube.com/watch?v=N6YdwzAvwOA&feature=related

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top