17

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!

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
user1787773
  • 888
  • 1
  • 11
  • 19

4 Answers4

8

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.

sdabet
  • 18,360
  • 11
  • 89
  • 158
  • Sorry, but I didn't understood the "keep it as fast as possible" part- this method only returns the array size right? – user1787773 Nov 26 '12 at 10:47
  • 1
    Sure. But you can override it as you like. The idea is to make sure you don't do any costly computation in it, since it is likely to be called many times and in UI thread. – sdabet Nov 26 '12 at 10:48
  • I didn't override it. all I do is return the array size. So I guess that's mean that the time that takes the listView to appear has got nothing to do with the getCount() that being called many times? – user1787773 Nov 26 '12 at 14:19
  • Probably not...You could use DDMS profiling tools to see what actually consumes CPU – sdabet Nov 26 '12 at 14:20
2

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).

Tushar
  • 261
  • 5
  • 17
0

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..

Kushal
  • 8,100
  • 9
  • 63
  • 82
0

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.

Kushal
  • 8,100
  • 9
  • 63
  • 82
Sterling Diaz
  • 3,789
  • 2
  • 31
  • 35