Activity_main:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "vertical" android:layout_width= "match_parent"
android:layout_height= "Match_parent" >
<textview
Android:id= "@+id/tv"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/app_name"
Android:textsize= "30DP"
android:layout_gravity= "Center"
android:layout_margintop= "20DP"/>
<button
Android:id= "@+id/btnstart"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "20DP"
android:text= "@string/hello_world"
/>
</LinearLayout>
Import Android.widget.Toast;
/**
* Created by DELL on 2016/7/13.
*/
public class Helloandroid extends activity{
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
This.setcontentview (R.layout.activity_main);
Findviewbyid (R.id.btnstart). Setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
System.out.println ("Don't touch me, okay! ");
Toast.maketext (Getapplicationcontext (), "Don't point me out, okay!" ", Toast.length_short). Show ();
}
});
}
}
Android for button events listening process