Performance++ View.findViewById() vs Activity.findViewById()
This is how you can speed up the loadingspeed of your application, as Activity's [font=Courier New]findViewByID[/font], like you probably used it up to now, is not that fast as you think. As you know the Android Layout-Structure is hierarchical (just like HTML and XML) and therefore the easiest way to represent it is a tree. The effect is bigger, as your layout gets more complex
Simpliefied Example Layout for this tutorial:
Using xml Syntax Highlighting
- <LinearLayout>
- <LinearLayout id="@+id/layout_outer">
- <TextView id="@+id/tv_inner_1"/>
- <TextView id="@+id/tv_inner_2"/>
- </LinearLayout>
- </LinearLayout>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
So if you do the following
So, getting the both TextViews of the both TextViews from the example before worked like this:
Using java Syntax Highlighting
- TextView tv_inner_1 = (TextView)this.findViewById(R.id.tv_inner_1);
- TextView tv_inner_2 = (TextView)this.findViewById(R.id.tv_inner_2);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Where the following is the faster way:
Using java Syntax Highlighting
- View layout_outer = this.findViewById(R.id.layout_outer);
- TextView tv_inner_1 = (TextView)layout_outer.findViewById(R.id.tv_inner_1);
- TextView tv_inner_2 = (TextView)layout_outer.findViewById(R.id.tv_inner_2);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Thats it 

Regards,
plusminus





