目录
我们知道, 一般在xml中可以设置button控件的点击事件处理的方法,可以在onClick属性的设置值,这个值对应的是加载此xml布局所在的Activity里面的一个方法名。
这里其实有一个快捷的操作方法,具体步骤如下。
首先,在xml中:
在在外层包裹的父布局中添加:
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.aiyang.stickydecoration.MainActivity"
在button控件中设置onClick的值为“myOnClick”:
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="myOnclick"
android:text="button" />