Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: is it efficient to store references to Views as member variables?

Tags:

android

view

If I have a view that I will be referencing with decent regularity (to change its visibility, etc...), is it more efficient to store this View as a member variable or to execute findViewById() each time I need a reference to it?

The member variable requires memory usage, while the method my take more time. Is anyone aware of an established best practice for this?

like image 811
ab11 Avatar asked Feb 03 '12 23:02

ab11


1 Answers

It is much more efficient to store the reference. The memory cost of the reference will be minimal (I don't remember the exact cost but it's in the order of 4 bytes.)

like image 161
Romain Guy Avatar answered Oct 27 '22 05:10

Romain Guy