I have an activity using the ActionBar listnavigation where a Framelayout shows the fragments associated with the navigation item clicked. So far, so good.
One of these fragments has a layout containing a FragmentTabHost. Specifically, the layout looks like this (simplified):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="12sp"
android:text="@string/user_creation_date"/>
<TextView
android:id="@+id/user_joinDate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textStyle="normal"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/profile_header">
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_height="match_parent"
android:layout_width="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="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</RelativeLayout>
In my fragment I initialize the FragmentTabHost in "onActivityCreated" as shown in the Android Documentation. Now to my problem; I receive the following error when I try to show the fragment:
E/AndroidRuntime(20242): FATAL EXCEPTION: main
E/AndroidRuntime(20242): java.lang.IllegalStateException: No tab known for tag null
I have found one thread that indicates that something fishy is going on with the FragmentTabHost, however it did not answer my question/problem: Android FragmentTabHost - Not fully baked yet?
Does anyone have similar experiences with the FragmentTabHost? Can someone explain this behavior?
Note: If I include the same fragment (no code changed) into the layout XML (by declaring <fragment>
) of a FragmentActivity I encounter no issues whatsoever.