国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > Android--页面跳转

Android--页面跳转

来源:程序员人生   发布时间:2015-03-11 08:40:08 阅读次数:2662次

1.页面1main.xml代码以下:

<?xml version="1.0" encoding="utf⑻"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="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>

页面2mylayout.xml代码以下:

<?xml version="1.0" encoding="utf⑻"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="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>

2.java程序以下:

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); // 生命周期方法 super.setContentView(R.layout.main); // 设置要使用的布局管理器 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.运行以下:


生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生