Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 420
user1787773 Avatar asked Nov 26 '12 10:11

user1787773


People also ask

What is a BaseAdapter in Android?

BaseAdapter, as it's name implies, is the base class for so many concrete adapter implementations on Android. It is abstract and therefore, cannot be directly instantiated. If your data source is an ArrayList or array, we can also use the ArrayAdapter construct as an alternative.

How to inflate ListView in Android?

In this case what you can do is, create a empty layout in your main activity xml. Set a ID for that. While inflating the listview, inflate it to that layout. In activity_main.


1 Answers

You can see here the different internal calls to the Adapter.getCount() method.

But you must keep in mind that you have no control on how this method is gonna be called.

It can be called multiple times and that's why you have to keep it as fast as possible.

like image 118
sdabet Avatar answered Sep 24 '22 22:09

sdabet