转载请注明出处:http://blog.csdn.net/u014657752/article/details/47294213
总结一下Button 点击事件onclick实现的四种方式;
方式一:
在xml中定义onclick属性
<span style="white-space:pre"> </span><Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onclick_button1"
android:text="方式一" />
<span style="white-space:pre"> </span>// 方式一
public void onclick_button1(View view) {
Toast.makeText(this, "方式一", Toast.LENGTH_SHORT).show();
}
方式二:
匿名内部类