View.findViewById() vs Activity.findViewById()

933 ワード

インターネットでView.findView ById()を見かけました Activity.findViewById()とは実行効率が異なります
通常、Activity.findViewById()は次のように使用されます.
TextView tv_inner_1 = (TextView)this.findViewById(R.id.tv_inner_1); 
TextView tv_inner_2 = (TextView)this.findViewById(R.id.tv_inner_2);

 View.findViewById() 次のようになります.
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);

 
彼らはすべて次の同じxmlに対して
<LinearLayout> 
     <LinearLayout id="@+id/layout_outer"> 
           <TextView id="@+id/tv_inner_1"/> 
           <TextView id="@+id/tv_inner_2"/> 
     </LinearLayout> 
</LinearLayout>