Overly Optimized
Overly Optimized

Reputation: 51

Optimize ListView backed up custom implemented BaseAdapter by caching View generated

I am showing enormous views on tabs formed with listview. ListView gets its data from an Adapter extending BaseAdapter. Every time, I move back and forth tabs, the Pager tends to create view in ListView again and again, wasting my precious CPU.

OK, so I tried using parentView.getChild(atIndex) in getView of BaseAdapter but that just ruins the view on scrolling the ListView.

Question, any way to optimize the performance by caching the view?

Regards,

Upvotes: 0

Views: 1289

Answers (1)

Cory Charlton
Cory Charlton

Reputation: 8938

The ListView already recycles views. The recycled view will be the View parameter in your adapters getView method.

You should also consider using the ViewHolder pattern to avoid a bunch of findViewById calls. See this link for more details http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

Edit: Here's some more references I was looking at tonight for optimizing ListViews:

http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/

http://www.youtube.com/watch?v=wDBM6wVEO70

Upvotes: 2

Related Questions