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
学会勇敢