Reputation: 6867
Im' trying to add a FragmentTabHost
inside a Fragment
(which is the content of another tab widget.
I used the following xml:
<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">
<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"/>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
And in my Fragment
's onCreateView()
method:
View basicSearchView = inflater.inflate(R.layout.search_layout, container, false);
try {
mTabHost = (FragmentTabHost) basicSearchView.findViewById(android.R.id.tabhost);
LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
mTabHost.setup(mLocalActivityManager);
TabHost.TabSpec tab = mTabHost.newTabSpec("my tab content");
tab.setContent(new Intent(getActivity(), JoinActivity.class));
tab.setIndicator("Test", getResources().getDrawable(R.drawable.search_pheeds_selector));
mTabHost.addTab(tab);
}
catch (Exception e) {
Log.e("Udi",e.getMessage());
}
return basicSearchView;
At first Igot the following error:
ERROR/Udi(25726): Must call setup() that takes a Context and FragmentManager
Afterwards I've changed the setup to:
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
And I got this error instead:
ERROR/Udi(25996): Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
Is there a proper way to put tab host inside a Fragment
?
Upvotes: 0
Views: 3710
Reputation: 87064
You haven't read the documentation for the FragmentTabHost
class which clearly states that FragmentTabHost
is a Special TabHost that allows the use of Fragment objects for its tab content.. So you can't setup the tabs to be activities and it would not make sense anyway as you're trying to have activities in fragments(it should be the other way around).
So modify your code to use fragments as the tabs content or use a normal TabHost
in an Activity
to continue using those activities as tabs(this option is deprecated and you should really go with the first option).
Is there a proper way to put tab host inside a Fragment?
In the documentation I've linked you have an example, if I'm not mistaken there are some examples in the support library's samples.
Upvotes: 1