动作条的标签上旋转片段片段、动作、标签

2023-09-12 02:40:15 作者:╭赐你滚蛋

我'建立与动作条和两个选项卡下面的应用程序。 一切工作正常,如果该设备/仿真器的心不是旋转。如果旋转,选项卡状态切换automaticale到TAB1(正常的,因为的onCreate 被调用),但含量不得到改变。如果我选择了新的方向选项卡,从选定片段 onCreateView()方法被调用,但视图不得到更新(留总是相同的)。任何提示?

在code。

主要活动:的

 动作条动作条= getActionBar();
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.Tab ATAB = actionbar.newTab()的setText(R.string.player)。
    ActionBar.Tab BTab = actionbar.newTab()的setText(R.string.stations)。

    片段AFragment =新AFragment();
    片段BFragment =新BFragment();

    PlayerTab.setTabListener(新MyTabsListener(AFragment));
    StationsTab.setTabListener(新MyTabsListener(BFragment));

    actionbar.addTab(ATAB);
    actionbar.addTab(BTab);
 

随着中显示了一个简单的TextView相同的选项卡。 TextView的简单的说,被选中的选项卡。

片段:的

  @覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
    //充气的布局该片段
    返回inflater.inflate(R.layout.a,集装箱,假);
}
 

分片布局,上面提到的,只包含有硬codeD TEXT一个TextView。 (仅用于测试目的)

主要布局看起来是这样的。

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>


    <的LinearLayout
        机器人:ID =@ + ID / fragment_container
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>
 < / LinearLayout中>

< / LinearLayout中>
 
横屏的时候请霸气一点

解决方案

解决。我已经重新创建每次片段,那并不这样做了解决它。

改变我的TabListener和 onTabSelected(TAB键,FragmentTransaction英尺) ft.add() ft.replace()

I'am build an app with an ActionBar and two Tabs below. Everything works fine if the device / emulator isnt rotated. If rotated, tab state switches automaticale to tab1 (normal, because onCreate get called) but the content dont get changed. If I select a tab in the new orientation, the onCreateView() method from the selected Fragment get called but the view dont get updated (stay always the same). Any Tips?

The code.

Main Activity:

    ActionBar actionbar = getActionBar();
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.Tab ATab = actionbar.newTab().setText(R.string.player);
    ActionBar.Tab BTab = actionbar.newTab().setText(R.string.stations);

    Fragment AFragment = new AFragment();
    Fragment BFragment = new BFragment();

    PlayerTab.setTabListener(new MyTabsListener(AFragment));
    StationsTab.setTabListener(new MyTabsListener(BFragment));

    actionbar.addTab(ATab);
    actionbar.addTab(BTab);

With identical tabs that display a simple textview. The textview simple say which tab is selected.

Fragments:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.a, container, false);
}

The Fragment layout, mentioned above, only contains a TextView with hardcoded Text. (Only for testing purposes)

The Main layout looks like this.

<?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" >


    <LinearLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
 </LinearLayout>

</LinearLayout>

解决方案

Solved. I have recreated the fragment everytime, doesnt do that anymore solved it.

Changed in my TabListener and onTabSelected(Tab tab, FragmentTransaction ft), ft.add() to ft.replace()