【发布时间】:2017-07-13 23:32:58
【问题描述】:
我是 Android Studio 的新手,我想快速访问按钮、图像视图、文本视图等视图。
到目前为止,我知道findViewById 的方法,这就是我正在做的创建轻松访问视图的方法:
Button btn1, btn2, btn3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.btn1=(Button)findViewById(R.id.btn1);
this.btn2=(Button)findViewById(R.id.btn2);
this.btn3=(Button)findViewById(R.id.btn3);
}
//then I simply use my defined vars
虽然它可以工作,但编写所有这些代码仍然很无聊(或者每次都必须使用findViewById,而且获取 id 的方式很繁琐,并且仍然添加演员表)。
这真的是最好的方法吗?
【问题讨论】:
标签: java android android-layout android-studio android-view