fairly new Android developer here.
I\'ve come across a strange problem that I\'m not sure how to work around. I\'ve read a lot of problems around here that sound lik
You are correct that ListView
is reusing views in different places on the screen. It's an optimization to keep memory use reasonable and speedy by not allocating new views all the time.
Chances are that you're using LiewView
incorrectly. Watch this talk on how to properly use ListView to get the whole story, but here's the highlights:
getView()
method or you will get strange behavior.getView(int, View, ViewGroup)
provides a view instance, populate its fields instead of inflating totally new views. Assuming you've correctly implemented getItemType()
, you'll always get the right View
type to repopulate. getView()
method as fast as you possibly can, and only do heavy lifting on other threads.getView()
doesn't necessarily mean the data will be displayed. The framework uses these for measurement purposes. Since the work could be thrown away, this is another reason to make sure that getView()
is as fast as you can make it.notifyDataSetChanged()
. Don't fiddle with the views directly, they'll be populated on the next UI loop when it gets redrawn.Having just spent a few days reworking a ListView
that was implemented naively, I feel your pain. The results have been worth it, though!