I have a ListView which can show some AnimationDrawables that are quite memory intensive. It’s unlikely more than 2 of these would be visible on screen, but there can easily be dozens in the items that make up the list.
My issues is that my ListAdapter seems to get called for every item in the list. I assume that this is so that the ListView can set it’s scroll height. But it means that I’m loading all those AnimationDrawables (that use lots of memory) that I don’t need.
Is there a way to determine if a call to ListAdapter is for a non visible row? This would allow me to skip loading these expensive objects that will likely never need to appear on screen.
ListViews recycle the rows so there are only a couple of non-visible rows at any time. That is what the getView method of the adapter does. It creates a View (if necessary), and sets the data for the current item. So if you have more items than visible rows, the view passed in to getView will not be null and should just get updated instead of created.