按钮的点击事件
activity_main.xml文件代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮"
android:onClick="click"
<!--此处就是为点击事件设置一个值-->/>
</LinearLayout>
Mainactivity.java文件代码
public void click(View view){
//点击按钮执行的事件,如点击按钮弹出一个消息框
//Toast.makeText(MainActivity.this, "我是弹出的消息内容" ,Toast.LENGTH_LONG ).show();
}