Android編程之頁面切換測試實例
本文實例講述了Android編程之頁面切換測試。分享給大家供大家參考。具體分析如下:
一、軟件平臺:
win7 + eclipse + sdk
二、設(shè)計思路:
兩個頁面:mian和ok,每個頁面上有一個按鍵,點擊則可以互相切換
三、源代碼:
main.xml源代碼:
<?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="下一頁面 "></Button> </LinearLayout>
ok.xml源代碼:
<?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="上一頁面 " android:id="@+id/button1"></Button> </LinearLayout>
makechoice源代碼:
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 when the activity is first created. */ @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(); } }); } //跳到ok頁面 public void jump2ok() { setContentView(R.layout.ok); //當有按鍵按下跳到main頁面 Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { jump2main(); } }); } //跳到main頁面 public void jump2main() { setContentView(R.layout.main); //當有按鍵按下跳到ok頁面 Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { jump2ok(); } }); } }
四、運行效果圖:
五、注意:
類R中存放的ID號為當前頁面的ID號,所以findViewById函數(shù)捕獲的控件也為當前頁面的控件
希望本文所述對大家的Android程序設(shè)計有所幫助。
- Android實現(xiàn)移動小球和CircularReveal頁面切換動畫實例代碼
- Android 實現(xiàn)無網(wǎng)絡(luò)頁面切換的示例代碼
- Android中TabLayout結(jié)合ViewPager實現(xiàn)頁面切換
- Android 中使用 ViewPager實現(xiàn)屏幕頁面切換和頁面輪播效果
- Android開發(fā)中ViewPager實現(xiàn)多頁面切換效果
- Android中TabLayout結(jié)合ViewPager實現(xiàn)頁面切換效果
- Android中使用TabHost 與 Fragment 制作頁面切換效果
- Android使用Fragment打造萬能頁面切換框架
- Android fragment實現(xiàn)多個頁面切換效果
相關(guān)文章
Android顯式啟動與隱式啟動Activity的區(qū)別介紹
為什么要寫顯式啟動與隱式啟動Activity,Android的Acitivity啟動大致有兩種方式:顯式啟動與隱式啟動,下面分別介紹2014-09-09Flutter listview如何實現(xiàn)下拉刷新上拉加載更多功能
這篇文章主要給大家介紹了關(guān)于Flutter listview如何實現(xiàn)下拉刷新上拉加載更多功能的相關(guān)資料,對于新聞列表數(shù)據(jù)的更新和加載更多是必不可少的,而實現(xiàn)下拉刷新與上劃加載更多的方式有很多種,需要的朋友可以參考下2021-08-08Android漲姿勢知識點之你沒用過的BadgeDrawable
現(xiàn)在Android中有許多的應(yīng)用仿蘋果的在應(yīng)用圖標上顯示小紅點,下面這篇文章主要給大家介紹了關(guān)于Android漲姿勢知識點之你沒用過的BadgeDrawable的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2022-09-09Android動態(tài)添加設(shè)置布局與控件的方法
這篇文章主要介紹了Android動態(tài)添加設(shè)置布局與控件的方法,涉及Android中布局與控件的相關(guān)操作技巧,需要的朋友可以參考下2016-01-01