标签:
首先,接口XML加入button响应函数 android:onClick="OnMyClick"
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:onClick="OnMyClick"
android:text="Button" /> public void Msg1( )
{
Toast toast = new Toast(this);
Toast toast1 = toast.makeText(this, "Hello World", Toast.LENGTH_LONG);
toast1.show();
}
public void OnMyClick(View v)
{
Msg1(); //消息提示显示
}
这样的加入响应函数的方法简单吧,感觉代码可读性比加入setOnClickListener监听用户单击操作要好多了。
setOnClickListener该方法允许代码比较多。太罗嗦。
版权声明:本文博客原创文章。博客,未经同意,不得转载。
AndroidAndroid程序提示和消息button响应事件
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/4635533.html