Software platform: Windows 7 + Eclipse + SDK
Design ideas:
Two pages: Mian and OK, there is a button on each page, click can switch to each other
Source:
Main.xml Source code:
The code is as follows |
Copy Code |
XML version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" android:orientation= "Vertical" Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" > <textview Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:text= "@string/hello" /> <button android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Next Page" >Button> Linearlayout> |
Ok.xml Source code:
The code is as follows |
Copy Code |
XML version= "1.0" encoding= "Utf-8"?> <linearlayout Xmlns:android= "Http://schemas.android.com/apk/res/android" Android:layout_width= "Match_parent" android:layout_height= "Match_parent" > <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Previous page" Android:id = "@+id/button1" >Button> Linearlayout> Makechoice Source code: Package com.makechoice;
Import Android.app.Activity; Import Android.os.Bundle; Import Android.view.View; Import Android.widget.Button;
public class Makechoice extends activity { /** called the activity is a. */ @Override public void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Button btn = (button) Findviewbyid (R.id.button1); Btn.setonclicklistener (New Button.onclicklistener () { @Override public void OnClick (View v) { Jump2ok (); } }); } Skip to OK page public void Jump2ok () { Setcontentview (R.layout.ok); When a button is pressed to jump to main page Button btn = (button) Findviewbyid (R.id.button1); Btn.setonclicklistener (New Button.onclicklistener () { @Override public void OnClick (View v) { Jump2main (); } }); }
Skip to Main Page public void Jump2main () { Setcontentview (R.layout.main); When a button is pressed to jump to the OK page Button btn = (button) Findviewbyid (R.id.button1); Btn.setonclicklistener (New Button.onclicklistener () { @Override public void OnClick (View v) { Jump2ok (); } }); } } |
Run Effect chart:
Attention:
The ID number stored in class R is the ID number of the current page, so the control that the Findviewbyid function captures is also the control of the current page