Android开发 代替 “(XXXX)findViewById()”

public class NActivity extends Activity{
   protected void onCreate(Bundle savedInstanceState){
      setContentView(R.layout.activity_main);
      Button button=getInstances(R.id.button1);
      Button button2=getInstances(R.id.button2);
      TextView tv1=getInstances(R.id.textview1);
      TextView tv2=getInstances(R.id.textview2);
   }
   protected <T extends View> T getInstances(int id) {
        return (T) findViewById(id);
    }
  
}
原文地址http://www.oschina.net/code/snippet_2410256_51108
posted @ 2015-09-28 16:32  戴杭林  阅读(567)  评论(0编辑  收藏  举报