组件拖入后,在属性里给其设置一个id,就可以在程序里找到它了,比如添加一个Button后,双击它可以看到有
<Button android:text="Button" android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
这时它的id就是 button1,我们在代码中可以这样写:
Button btn =(Button)findViewById(R.id.button1);
<Button android:text="Button" android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
这时它的id就是 button1,我们在代码中可以这样写:
Button btn =(Button)findViewById(R.id.button1);