Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reuse inflated views

Tags:

android

I am building a complex view based on dynamic data. Depending on the number of data elements in collections I am adding more views. Each of these subviews are complex and get inflated in the loop through the data collection.

This is of course inefficient and I would like to figure out a way to inflate the subview only once and then reusing them instead. Is this possible somehow?

PS: I do not want to build up the subviews in code (I know I could) because that would make things even messier due to the complexities and number of subviews, but if the performance would increase considerably I might take a look at that.

PPS: There is no visible performance problem but traceview that most of the time is spent inflating and if I can make it faster I would love to ;-)

like image 572
Manfred Moser Avatar asked Nov 05 '22 05:11

Manfred Moser


1 Answers

you can check out the Google IO Session entitled 'The world of ListView'.

It explains very nicely how to prevent inflating the same view again and again, and how to reuse a particular view if it has been already inflated earlier.

Here is the link.

http://www.google.com/events/io/2010/sessions/world-of-listview-android.html

You can either download the .pdf file or view the video.

Hope it helps.

Regards, Mahendra Liya.

like image 71
Mahendra Liya Avatar answered Nov 15 '22 08:11

Mahendra Liya