Snake
Snake

Reputation: 14658

Is findViewByID time or resource consuming

In my application of tabs, everytime the tab is changed, I use the findViewByIDs of the views/elements of that tab (16 items). I was wondering is it slow, battery drainer or time consuming to use this method? Or should I store all the 16 values * 4 tabs as class variables and just use them when I need them?

Whats you design experience. Thank you

Upvotes: 0

Views: 880

Answers (2)

James Black
James Black

Reputation: 41858

IF you are trying to optimize you may want to look at this article: http://blog.stylingandroid.com/listview-part-4/ for ideas, but one thing pointed out is that findViewById can be a problem, so you can either cache what you have found or use the Holder pattern, found in http://commonsware.com/Android/, but you may find some of the other suggestions to be helpful also.

Upvotes: 3

Frank Cheng
Frank Cheng

Reputation: 6186

AchI think it is. You can creat a viewcache to store the views you for earlier. Then you can just findviewbyid just once for everyview.

Upvotes: 1

Related Questions