2011-11-05 76 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