A001.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns: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 <Button8 Android:id= "@+id/btnshow"9 Android:layout_width= "Wrap_content"Ten Android:layout_height= "Wrap_content" One Android:text= "Show Toast" /> A - </LinearLayout>
A001.java
1 PackageCom.example.main;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 ImportAndroid.view.View;6 ImportAndroid.view.View.OnClickListener;7 ImportAndroid.widget.Button;8 ImportAndroid.widget.Toast;9 Ten Public classA001extendsActivity { One A @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); the Setcontentview (r.layout.a001); - - //Get Button control -Button Button =(Button) Findviewbyid (r.id.btnshow); + - //button click event +Button.setonclicklistener (NewOnclicklistener () { A at @Override - Public voidOnClick (View v) { - //Click on the button to show the toast -Toast.maketext (A001. This, the button control, Toast.length_short). Show (); - } - }); in } -}
The Android--button control uses