A total of 2 layout:main.xml and Other.xml;2 Activity:mainactivity.java,otheractivity.java
Rewrite OnCreate in mainactivity, line 6th set Button Listen ~
1 Public voidonCreate (Bundle savedinstancestate) {2 Super. OnCreate (savedinstancestate);3 Setcontentview (r.layout.main);4LOG.V ("Mainactivity", "OnCreate");5BTN =(Button) Findviewbyid (R.ID.MAIN_BTN);6Btn.setonclicklistener ( This);7 //this.finish ();//End Current Mainactivity8}
Here is the implementation of the button listener: that is, when the button is pressed, jump to another page:
1 @Override2 Public voidOnClick (View arg0) {3 if(arg0 = =btn) {4Intent Intent =NewIntent ();5Intent.setclass ( This, Otheractivity.class);6 This. StartActivity (intent);7 }8}
Another activity is similar:
1 public void OnCreate (Bundle savedinstancestate) { 2 super .oncreate (savedinstancestate); 3 Setcontentview (r.layout.other); 4 log.v ("mainactivity", "OnCreate" 5 btn =6 Btn.setonclicklistener (this " Span style= "color: #000000;" >); 7 }
1 Public void OnClick (View arg0) {2 if (arg0 = = btn) {3 This . Finish (); 4 }5 }
Some people will think otheractivity why that look, for the moment I do not know, first put his XML file:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Fill_parent"5 Android:layout_height= "Fill_parent"6 >7 <TextView8 Android:layout_width= "Fill_parent" 9 Android:layout_height= "Wrap_content" Ten Android:text= "@string/otheractiviy_hello" One /> A <Button - Android:layout_width= "Fill_parent" - Android:layout_height= "Wrap_content" the Android:text= "@string/otheractiviy_btnclose" - Android:id= "@+id/other_btn" - /> - </LinearLayout>
This article link: http://www.cnblogs.com/zjutlitao/p/4229540.html
More Highlights: http://www.cnblogs.com/zjutlitao/
[Android] 1, page jump + button monitoring