Я пытаюсь добавить TabHost внутри фрагмента, как в примере, получив NullPointerException при вызове
mTabHost.setup()
что может быть проблемой? код ниже
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tabs_layout,container,false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("tab1"),
Fragment1.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("tab2"),
Fragment2.class, null);
return rootView;
}
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="@+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>