Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView getView() called too often

I have a ListView with custom Adapter. To be honest, I have many of them at the same time on screen, and my Tegra 3 device started to lag, what made me really confused... I found than in each ListView's Adapter the getView() method is called for all visible rows every time any animations runs on screen. That gives me like few hundreds of calls per second! Digging more, most of these calls are due to measure() and onMeasure() calls of ListViews' parents, and - this is tke key - they are useless, because all the layouts of my ListViews have const size.

So my question is: how to eliminate these calls? Of course I want to leave proper calls alone (caused by adding items to Adapter and notifyDataSetChanged() ).

I've tried almost anything, but either the whole list doesn't draw itself (when I overriden it's onMeasure() and forced to returned const size without calling super.onMeasure()) or stops updating at some time.

like image 202
Fenix Voltres Avatar asked Dec 21 '22 00:12

Fenix Voltres


1 Answers

How you implemented the getView() method? If you implement it in the correct way there should be nearly no lagging.

Check out this really really good video:

  • http://www.youtube.com/watch?v=wDBM6wVEO70
  • Slides: http://dl.google.com/googleio/2010/android-world-of-listview-android.pdf

As Romain said, work with it not against it. Best is to leave measure() alone and focus on your adapter.

like image 148
wbb Avatar answered Jan 09 '23 17:01

wbb