android--page Jump

Source: Internet
Author: User

1. The Main.xml Code of the page is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent "    android:o rientation= "vertical" >    <textview        android:id= "@+id/text1"        android:layout_width= "Fill_parent"        android:layout_height= "wrap_content"        android:text= "@string/layout1"/>    <button        android: Id= "@+id/btn1"        android:layout_width= "fill_parent"        android:layout_height= "Wrap_content"        android: Text= "Go to Layout2"/></linearlayout>

Page two mylayout.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent "    android:o rientation= "vertical" >    <textview        android:id= "@+id/text2"        android:layout_width= "Fill_parent"        android:layout_height= "wrap_content"        android:text= "@string/layout2"/>    <button        android: Id= "@+id/btn2"        android:layout_width= "fill_parent"        android:layout_height= "Wrap_content"        android: Text= "Go to Layout1"/></linearlayout>

The 2.java program is as follows:

Package Org.lxh.demo;import Android.app.activity;import Android.app.alertdialog;import android.app.Dialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.view.onfocuschangelistener;import Android.widget.Button; Import Android.widget.edittext;import Android.widget.textview;public class Hello extends Activity {private Button btn1 = null;//private Button btn2=null;public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Life cycle Method Super.setcontentview (R.layout.main); Set the layout manager to use THIS.BTN1 = (Button) Super.findviewbyid (R.ID.BTN1); Btn1.setonclicklistener (New Button.onclicklistener () {public void OnClick (View arg0) {jumpToLayout2 ();}});} public void JumpToLayout2 () {Setcontentview (r.layout.mylayout); Button btn2 = (button) Super.findviewbyid (R.ID.BTN2); Btn2.setonclicklistener (new Button.onclicklistener () {public void OnClick (View arg0) {jumpToLayout1 ();}});} Public VOID jumpToLayout1 () {Setcontentview (r.layout.main); Button btn1 = (button) Super.findviewbyid (R.ID.BTN1); Btn1.setonclicklistener (new Button.onclicklistener () {public void OnClick (View arg0) {jumpToLayout2 ();}});}}

3. Run as follows:


android--page Jump

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.