2011-11-05 38 views
2

對不起,如果問題不清楚。在我的應用程序中,我在acion欄上有3個選項卡,此外每個選項卡都有一個帶有兩個片段的單獨xml佈局。對於前兩個選項卡,佈局類似,但第三個選項卡具有單獨的xml佈局。在第一個選項卡中,我將進行其他調用並獲取要顯示的數據。左側的片段顯示文件夾列表,右側的片段顯示文件列表。 Tab2是相同的,但它顯示來自SD卡的數據。它基本上是文件管理器。片段和右側設計

第三個選項卡是與前兩個片段完全不同的搜索頁面。

以下是我的問題。

  1. 我想知道如果我可以爲每個選項卡使用不同的活動,這是正確的設計嗎?
  2. 因爲我正在使用主要活動來創建碎片所需的佈局,所以我現在遇到了第三個選項卡的問題,原因是xml佈局和片段類(代碼)在第三個選項卡中完全更改。這裏是xml文件的內容。

佈局前兩個選項卡:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/frags1"> 
    <fragment class="TitlesFragment" 

      android:id="@+id/browse_title" 
      android:visibility="gone" 
      android:layout_marginTop="?android:attr/actionBarSize" 
      android:layout_height="match_parent" android:layout_width="320dip"/> 

    <fragment class="ContentFragment" 

      android:id="@+id/browse_content" 
      android:visibility="gone" 
      android:layout_marginTop="?android:attr/actionBarSize" 
      android:layout_height="match_parent" android:layout_width="match_parent"> 
    </fragment>  
</LinearLayout> 

Layout for the third tab: 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/settings" 
android:background="@drawable/window" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:baselineAligned="true"> 

    <fragment class="SearchFragment"     
      android:id="@+id/search_title" 
      android:visibility="gone" 
      android:layout_marginTop="?android:attr/actionBarSize" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:layout_width="700dp" 
      android:paddingRight="5dip"/> 

    <fragment class="SearchContentFragment" 
      android:id="@+id/searchbrowse_content" 
      android:visibility="gone" 
      android:layout_marginTop="?android:attr/actionBarSize" 
      android:layout_weight="1"  
      android:layout_width="match_parent"  
      android:layout_height="match_parent"/>  
</LinearLayout> 

所以,當我從第一個選項卡單擊以TAB3(搜索)UI正確renedered,但我不能從TAB3回來TAB1。爲了解決這個問題,我將XML文件中的片段移動到了主要活動代碼中。我很擔心,因爲我不確定這是否是正確的設計。

此外,下面是代碼片段。

switch(nTabSelected) 
{ 
    case ConnectedConstants.BROWSE: 
    if (getFragmentManager().findFragmentById(R.id.browse_title) == null) 
    { 
    setContentView(CreateMainLayout()); 
    } 
    TitlesFragment titleFrag = (TitlesFragment) getFragmentManager() 
    .findFragmentById(R.id.browse_title); 
    titleFrag.resetCurPosition(); 
    titleFrag.setCategory(nTabSelected); 
    if (bLoggedin) { 
    titleFrag.selectPosition(0); 
    } 
    break; 

每次用戶點擊標籤頁時,我都會爲該標籤的xml充氣。 接下來的問題,我說,我從服務器獲取數據使用休息調用來更新tab1片段,因爲我使用tab1和tab2的列表片段,我只是做setListAdapter,但與此我想了解,如果我可以實現一個後臺堆棧,或者我需要一個新的片段事務,每個列表項目單擊然後將片段添加到後臺堆棧。

讓我知道,如果我的問題仍然聽不清楚。

感謝, 戒

+0

你需要更具體。縮小你的問題。 –

+0

如果您需要幫助,請發佈關於您提到的「崩潰問題」的logcat輸出。 – Tapirboy

+0

對不起,如果問題不明確。 – user1031459

回答

1

我們做這一切的錯,我們試圖在每個選項卡中點擊膨脹不同的XML文件,最簡單的辦法是讓單一XMLhaving所有碎片和隱藏/顯示他們點擊操作欄上的標籤。

我們解決了一個主要活動,四個不同的選項卡,一個主要的XML顯示所有片段(8)。

謝謝, Harsha