This is not an issue, there is absolutely no guarantee on the order in which getView()
will be called nor how many times. In your particular case you are doing the worst thing possible with a ListView
by giving it a height=wrap_content
. This forces ListView
to measure a few children out of the adapter at layout time, to know how big it should be. This is what provides ListView
with the convertViews
you see passed to getView()
even before you scroll.
Try with match_parent
on the layout_height
property of the list view. It will prevent getView()
to be called so often.
I got rid of this issue when I changed both layout_width and layout_height to match_parent (changing only layout_height didn't help).
Helpful note watch out if you have nested items. You've got to change the "highest" one to match_parent. Hope it helps someone.
I am not able to answer your "Why" question but i definitely have a solution to the problem of the irritating "ListView items repeating" problem(if you have items in ur collection which are more than the screen height).
As many people above have mentioned, keep the android:layout_height property of the ListVew tag as fill_parent.
And about the getView() function, the solution is to use a static class called ViewHolder. Check out this example. It successfully does the task of adding all the items in ur Array or ArrayCollection.
Hope this helps friends!!
Best Regards, Siddhant
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