Meine Klassen
FragmentTabs - das Fragment, das meinen FragmentTabHost enthält
Seine onCreateView-Methode
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentTabHost = new FragmentTabHost(getActivity());
fragmentTabHost.setup(getActivity(), getFragmentManager());
fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab1").setIndicator("Tab1"), Fragment1.class, null);
fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab2").setIndicator("Tab2"), Fragment2.class, null);
return fragmentTabHost;
}
Die Aktivitätsklasse XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.studio3s.myapplication.TestActivity">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.studio3s.myapplication.FragmentTabs"
android:id="@+id/fragment"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Ich sehe keine Tabs auf meiner Aktivität .. wo kann das Problem sein?
Fragment1 und 2 Klassen sind nur leere Fragmente mit nur einer Textansicht.
Antworten:
3 für die Antwort № 1benutze stattdessen childFragmentManager FragmentManager, d. h.
fragmentTabHost.setup(getActivity(), getChildFragmentManager(), R.id.content);
Hier conent
Hier wollen Sie das aktuelle Fragment anzeigen. Jetzt enthält Ihr Container Tabs, die Sie in fragmentTabHost hinzufügen