I am working on an Android app with a listView and am in the process of optimizing it. It uses a custom cursor adapter in one activity and I noticed that bindview() was firing twice for each row of the list. While researching the BindView() and NewView() methods here, I read in a post that having Wrap_Content for the width of my listview was a bad idea. I switched it to Fill_Parent and viola now bindview() and newview() each only fire once for each item.
So that I can better understand the internals of the Andorid OS, I would like to know why Wrap_Content caused bindview() to fire multiple times.
I have done several searches on Google, the android developer docs and here with no luck.
Any response is really appreciated.
Thanks, George
If I recall correctly from a video from Google I/O, setting the width (or height) of a ListView
to wrap_content
will cause it to measure the first 3 items and base its dimensions off of those. In order to measure those first 3 items, it must call bindView()
to populate them. Once it has measured, it will populate fully and call bindView()
again on those first 3 and any subsequent.
This is due to the fact that the ListView
only keeps in memory what is on the screen when you may have potentially an infinite number of items in the list. It is not designed to wrap_content
to your largest item because it could be stuck in the drawing phase forever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With