今天学习监听按钮的点击事件,通过外部类来实现监听。
首先在layout布局文件中拖拉两个button按钮,设置layout_width="match_parent",两个按钮分别设置为按钮1和按钮2。
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮2" />
然后在主类中重写onCreat方法,并且调用父类的onCreate方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
定义两个Button对象&#