a001.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <Button 8 android:id="@+id/btnShow" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:text="显示吐司" /> 12 13 </LinearLayout>
A001.java
1 package com.example.main; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.View.OnClickListener; 7 import android.widget.Button; 8 import android.widget.Toast; 9 10 public class A001 extends Activity { 11 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.a001); 16 17 // 获取 button 控件 18 Button button = (Button) findViewById(R.id.btnShow); 19 20 //button 点击事件 21 button.setOnClickListener(new OnClickListener() { 22 23 @Override 24 public void onClick(View v) { 25 //点击 button 显示吐司 26 Toast.makeText(A001.this, "按钮控件", Toast.LENGTH_SHORT).show(); 27 } 28 }); 29 } 30 }
时间: 2024-10-24 20:38:25