3

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

jakehschwartz
  • 1,005
  • 2
  • 13
  • 32
  • 1
    Are you overriding the getview method of your adapter? If so, show what you are doing. – Cheryl Simon Nov 30 '10 at 21:18
  • Jake, I had the same issue and i found the solution here: http://stackoverflow.com/questions/2955218/listview-in-arrayadapter-order-gets-mixed-up-when-scrolling?rq=1 – Reiksiel Nov 09 '13 at 15:49

1 Answers1

5

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

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
  • Awesome. I realized I was recycling but I wasn't reseting the fields so that it was just displaying the same things as before. Thanks. – jakehschwartz Dec 02 '10 at 19:14