Now someone told me that it's much better to do it usning FragmentTabHost.
Well, I did say "FragmentTabHost
is probably the least popular of the 3, though it's closest to your current code."
Where did they get R.id.realtabcontent ?
That's the ID of a widget in a layout. Specifically it would be in R.layout.fragment_tabs
, which the documentation neglects to show.
Fortunately, this appears to be from the support package samples, and that layout can be found here, with the definition at the time of this writing as:
<android.support.v4.app.FragmentTabHost
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="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>
And another thing that isn't explained; how should the xml of the tab activity look?
See above.
Do I need to adjust it to FragmentTabLayout or is it good this way?
Well, if nothing else, you will need to replace TabHost
with FragmentTabHost
.
But, frankly, FragmentTabHost
is worse off, documentation-wise, than I was remembering when I commented on your earlier question.