tutorial - how to set data in listview in android




Why does getCount in adapter is being called so many times? (3)

I have a custom list and it takes few minutes to show-up. When I was trying to check where the problem is, I saw that even when I have only 1 item in the list, the method getCount() is being called 5 times, getVIew() is being called once, an then getCount() is being called to more time. Overall getCount() is being called 7 times. Does that makes sense?

Thank you!


getCount() is called too many times because App-USER can update its list ( can add data in its storage ) anytime and thats why we return , (storage).size() (total number of elements).


Adapter getCount() method will be called in following cases.

1) when setting the adapter to List view/ Grid View.

2) when we call notifyDataSetChanged on Adapter.

So, check in your code, you might be doing the above cases more time or recursively..


You should have a search button that updates the adapter when searching. That method get called drawing the view multiple times, if inside that method you have a setAdapter, then, getCount will be called many times, and will ended up returning 0 and you view will not be filled.





listadapter