» 首頁 » 討論區 » Android程式設計 »android 換頁問題

android 換頁問題

發表人: ooaaa
積分: 158
發表時間: 2011-09-09 03:02:27
大大...請教一下換頁的問題...

我想 在activity1 <->activity2 <-> activity 3

比如 我的activty 1 是簡介.... activity 2 是留言...activity3 是地圖

我想按簡介就會list 簡介的資料
我想按留言就會有留言的資料以及留言
activity 3 就是顯示地圖

請大大給我方向以及範例....無言感激

P.S. 不是按鈕 按一下 去activity1 之後返回 再按按鈕2 這樣....是一個頁面裡有幾個頁面 可以快速的切換
發表人: Seachaos
積分: 2432
發表時間: 2011-09-09 09:39:15
你說的可能是TabView
可以參考看看使用TabView (頁籤的切換)
發表人: ooaaa
積分: 158
發表時間: 2011-09-09 17:26:18
類似這個用法...但我看別人的應用程式 做得很飄亮....但是 也是類似這種用法...

大大另外再問一個問題...

就是 我是想做一個留言版....我能用listview list出 所有留過言的人...但不知道怎樣在listview 裡弄一個留言的按鈕...我想過用menu 的方法...但有沒有更好更飄亮的方法??

還有還有...就是intent 可以傳值到 下下下一個頁面嗎...

就是 activity 1..我想傳一個id 值去 activity5... 之後activity 2 又想傳一個值去 activtiy5... 之後activity 5 得到2個值之後..列出某個東西...應該要怎樣做??有範例嗎 ?
發表人: Seachaos
積分: 2432
發表時間: 2011-09-10 20:36:06
如果你有資訊要一直傳的話可以考慮用state的變數
建一個獨體類別,當做Global變數區就可以了

ListView加Button的話 (你的Button應該是留言吧? )
可以試看看把
LinearLayout換成RelativeLayout
然後 Button 設定 android:layout_alignParentBottom="true"
這樣的話Button 就會貼在畫面下了
發表人: ooaaa
積分: 158
發表時間: 2011-09-11 00:49:51
[quote]
如果你有資訊要一直傳的話可以考慮用state的變數
建一個獨體類別,當做Global變數區就可以了

[/quote]

可以給我簡單的範例參考嗎....感恩
發表人: ooaaa
積分: 158
發表時間: 2011-09-11 01:38:08
我想 我是想使用者持續登入狀態...有方法可以讓使用者登入後 再按其他頁面 都會持續這個使用者嗎??
發表人: Seachaos
積分: 2432
發表時間: 2011-09-11 21:14:19
可以
舉例來說
我建一個Class

[sea:javaCode]
public class User{
public static boolean login = false;
public static int userId = -1;
}
[/sea]

那我就可以在各Activtiy存取User了,不用new User

例下:
[sea:javaCode]
if(User.login==true){
...
}

User.userId = 100....
[/sea]

因為User裡的login和userId是static(靜態的,不用new出來,也就是global了)
這是比較簡單的做法,詳細的可以用到獨體模式
發表人: ooaaa
積分: 158
發表時間: 2011-09-15 19:29:48
[sea:javaCode]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/wqrewrqwre" >
<ImageView android:layout_height="wrap_content"
android:id="@+id/imageviewa"
android:layout_width="wrap_content"
android:src="@drawable/icon"></ImageView>
<TextView android:layout_height="wrap_content" android:layout_marginLeft="6dip" android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/texttext1" android:layout_marginTop="6dip" android:layout_width="wrap_content"></TextView>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/zsert"
android:orientation="horizontal">
</LinearLayout>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/texttext2" android:layout_below="@+id/wqrewrqwre" android:layout_alignParentLeft="true"></TextView>
<Button android:id="@+id/backbtn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="返回" android:layout_alignTop="@+id/combuton" android:layout_alignParentRight="true" android:layout_marginRight="32dp"></Button>
<Button android:id="@+id/combuton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="我要發言" android:layout_alignParentBottom="true" android:layout_toLeftOf="@+id/backbtn" android:layout_marginBottom="36dp"></Button>
</RelativeLayout>

[/sea]
我要怎樣改才能把BUTTON 固定在右下方??
我是只要一個按鈕就可以...不用每個listview 裡都有button...我應該怎樣改呢??請大大指教
發表人: Seachaos
積分: 2432
發表時間: 2011-09-15 23:39:20
您好:
你上面的是Adapter用的Layout吧?

RelativeLayout是用在主Layout的
[sea:javaCode]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<ListView >
<!-- List View的內容 -->
</ListView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/texttext2" android:layout_below="@+id/wqrewrqwre" android:layout_alignParentLeft="true"></TextView>
<Button android:id="@+id/backbtn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="返回" android:layout_alignTop="@+id/combuton" android:layout_alignParentRight="true" android:layout_marginRight="32dp"></Button>
<Button android:id="@+id/combuton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="我要發言" android:layout_alignParentBottom="true" android:layout_toLeftOf="@+id/backbtn" android:layout_marginBottom="36dp"></Button>
</RelativeLayout>
[/sea]
改成這樣在用ListView應該就可以了
如果內容太多的話可能你會看不到,這時可以用scrollView
發表人: ooaaa
積分: 158
發表時間: 2011-09-16 20:00:18
對...我是Adapter用的Layout...如果我不用listview...用adapter..有沒有方法在這個layout 裡加入一個button 固定在右下方??
發表人: Seachaos
積分: 2432
發表時間: 2011-09-17 10:35:28
[quote]ooaaa 提到:
對...我是Adapter用的Layout...如果我不用listview...用adapter..有沒有方法在這個...[/quote]
可以的
我上面的XML是Main的Layout (例如)
裡面有ListView , 把你上面的XML修改過後就可以給Adapter用
(簡單的說,有兩個Layout,一個是外面的,一個是ListView的)
RelativeLayout和bottom的button是放在外面用的
發表人: ooaaa
積分: 158
發表時間: 2011-09-22 11:08:35
感恩...我可以用了