活动选项卡内的Android MasterDetail布局避免嵌套片段

活动选项卡内的Android MasterDetail布局避免嵌套片段,android,android-layout,android-fragments,android-actionbar,android-fragmentactivity,Android,Android Layout,Android Fragments,Android Actionbar,Android Fragmentactivity,我对android的片段不是很精通。在我的上一个项目中,我使用了TabActivity,但由于它的不受欢迎,现在我开始使用片段实现ActionBar 以下是我的Tab类的代码: public class TabInterventoClass extends FragmentActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我对android的片段不是很精通。在我的上一个项目中,我使用了TabActivity,但由于它的不受欢迎,现在我开始使用片段实现ActionBar

以下是我的Tab类的代码:

public class TabInterventoClass extends FragmentActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);

    Tab tab = actionBar.newTab()
            .setText("Dati")
            .setTabListener(new TabListener<DatiFragment_>(this, "dati", DatiFragment_.class));
    actionBar.addTab(tab);

    tab = actionBar.newTab()
            .setText("Sistemi alimentazione")
            .setTabListener(new TabListener<SistemaAlimentazioneFragment_>(this, "Sistemi alimentazione", SistemaAlimentazioneFragment_.class));
    actionBar.addTab(tab);

    tab = actionBar.newTab()
        .setText("Home")
        .setTabListener(new TabListener<HomeFragment_>(this, "home", HomeFragment_.class));
    actionBar.addTab(tab);
}
(删除标签和
的id可以解决问题。但是我需要一种方法来获取它,以便刷新他的适配器!因此我显示/隐藏片段,而不是附加/分离)。幸运的是,我必须修复方向,这样在使用“显示/隐藏”更改方向时,就不会出现重叠片段的问题

这里是第一个选项卡DisplayDatiFragment,它扩展了Fragment类

这看起来还可以

这是第二个选项卡,它显示了StrumentiFragment。布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
       android:layout_height="fill_parent"
       android:layout_width="wrap_content"
       android:gravity="center_vertical"
       android:text="Sistema di alimentazione:" />

    <Spinner 
        android:id="@+id/sistemiDiAlimentazione"
        android:layout_height="fill_parent"
        android:layout_width="wrap_content" />

     <Button 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Aggiungi"
        android:id="@+id/addSistemaAlimentazione" />           

</LinearLayout>
<LinearLayout
    android:baselineAligned="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <fragment android:name="it.cpmapave.mt.ui.intervento.SistemaAlimentazioneListFragment_"
        android:layout_width="0dp"
        android:tag="sistemiList"
        android:layout_height="match_parent"
        android:layout_weight="1" />
    <FrameLayout android:id="@+id/item_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3" />
</LinearLayout>

从片段A中的微调器添加元素将更新片段列表B。从片段列表B中选择元素将更新片段C中的详细信息

我认为这个问题可能是由嵌套片段引起的。。但我不知道我是如何用另一种方式设计的。。也许我把事情弄得比实际情况更难

我忽略了在代码中说明我正在使用ActionBarSherlock,只是因为我认为这不是我问题的原因

所以最后。。问题是:


我需要获得第二张图中所示的功能布局。但我只是通过筑巢碎片得到的。。我必须避免这样做。我该怎么办?

谢谢你的回复
Marco

我已经解决了将每个帧放入帧布局中,在需要时显示/隐藏的问题

我还为创建ActionTab的类定义了自定义布局:

<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TabWidget
        android:id="@android:id/tabs"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"/>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <LinearLayout
        android:baselineAligned="false"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+android:id/navtabcontent"
            android:layout_width="0dp"
            android:layout_height="600dp"
            android:layout_weight="1"/>
        <FrameLayout
            android:id="@+android:id/realtabcontent"
            android:layout_width="0dp"
            android:layout_height="600dp"
            android:layout_weight="3"/>
    </LinearLayout>
</LinearLayout>


我希望这对某人有用

在我的例子中,隐藏和显示在选项卡活动中是不好的做法,因为片段不会被暂停和恢复。。因此,我的值不会存储到db中。我需要获得第二张图中所示的功能布局。但我只是通过筑巢碎片得到的。。我必须避免这样做。我该怎么办?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
       android:layout_height="fill_parent"
       android:layout_width="wrap_content"
       android:gravity="center_vertical"
       android:text="Sistema di alimentazione:" />

    <Spinner 
        android:id="@+id/sistemiDiAlimentazione"
        android:layout_height="fill_parent"
        android:layout_width="wrap_content" />

     <Button 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Aggiungi"
        android:id="@+id/addSistemaAlimentazione" />           

</LinearLayout>
<LinearLayout
    android:baselineAligned="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <fragment android:name="it.cpmapave.mt.ui.intervento.SistemaAlimentazioneListFragment_"
        android:layout_width="0dp"
        android:tag="sistemiList"
        android:layout_height="match_parent"
        android:layout_weight="1" />
    <FrameLayout android:id="@+id/item_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3" />
</LinearLayout>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TabWidget
        android:id="@android:id/tabs"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"/>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <LinearLayout
        android:baselineAligned="false"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+android:id/navtabcontent"
            android:layout_width="0dp"
            android:layout_height="600dp"
            android:layout_weight="1"/>
        <FrameLayout
            android:id="@+android:id/realtabcontent"
            android:layout_width="0dp"
            android:layout_height="600dp"
            android:layout_weight="3"/>
    </LinearLayout>
</LinearLayout>