Fragments not visible after tab-switch in nested FragmentTabHost
<p>I have a FragmentTabHost in the layout of one of my fragments (let's call it parentFragment). Now, I initialize each of the fragments that go in the tabhost programmatically in onCreateView of the parentFragment. When the parentFragment is created everything seems to work fine and it is showing the fragment of the first tab correctly.</p>

<p>But as soon as I switch the tab once, the fragments disappear (I can see the background color of the tabhost, but no content of the tabcontent-container). Also the first fragment is gone when I switch back to it. The fragments are actually being created as my logging shows, but they are not visible.</p>

<p>I assume it has to do with (re)creating the fragments, since I also tried using a ViewPager with a FragmentPagerAdapter. There I could happily switch between the first two fragments (preloaded due to setOffscreenPageLimit() ==1), but fragments (re)created beyond that were blank as well.</p>

<p>Any thoughts anyone??</p>

<p>Here is some of my code:</p>

<p><strong>Extract of parentFragment's XML:</strong></p>

<pre><code>...
            &lt;android.support.v4.app.FragmentTabHost
                android:id="@android:id/tabhost"
                android:layout_width="match_parent"
                android:layout_height="match_parent" &gt;

                &lt;RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" &gt;

                    &lt;TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_alignParentTop="true" /&gt;

                    &lt;FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="0dp"
                        android:layout_height="0dp" /&gt;

                    &lt;FrameLayout
                        android:id="@+id/realtabcontent"
                        android:layout_below="@android:id/tabs"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" /&gt;
                &lt;/RelativeLayout&gt;
            &lt;/android.support.v4.app.FragmentTabHost&gt;
...
</code></pre>

<p><strong>Extract of parentFragment's XML:</strong></p>

<pre><code>...
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView");
        ViewGroup layoutContainer = (ViewGroup) inflater.inflate(R.layout.fragment_app_details_test, container, false);

            tabHost = (FragmentTabHost) layoutContainer.findViewById(android.R.id.tabhost);
        tabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("TAB1"),
                FragmentSubTab1.class, null);
        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("TAB2"),
                FragmentSubTab2.class, null);
        tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("TAB3"),
                FragmentSubTab3.class, null);

        return layoutContainer;
    }
...
</code></pre>

<p><strong>Simple layout inflation in sub tab's fragment:</strong></p>

<pre><code>...
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup layoutContainer = (ViewGroup) inflater.inflate(R.layout.subfragment1, container,
                false);

        initUi(layoutContainer);
        return layoutContainer;
    }
...
</code></pre>
