android:onClick vs setOnClickListener
为Android Widgets添加点击事件处理函数又两种方法,一个是在Xml文件中添加onClick属性,然后在代码中添加对应的函数。另一个是直接在代码中添加setOnClickListener函数。两者什么区别呢?以Button控件为例讲解一下。 方法一 在Xml中添加onClick属性 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/mybutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Press Me" android:onClick="buttonCli...