I wrote some app that contain TabHost. Each tab contain a LinearLayout - and i want to add some different exist Fragment that i created to each of the tab
How to do it ?
private void setNewTab(Context context, TabHost tabHost, String tag, String title, int contentID ){
TabHost.TabSpec tabSpec = tabHost.newTabSpec(tag);
tabSpec.setIndicator(title);
Fragment newFragment = new ActionFragment ();
tabSpec.setIndicator(newFragment.getView());
tabSpec.setContent(contentID);
tabHost.addTab(tabSpec); // after this line i get an exception
}
<TabHost 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_light">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 1 Content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 2 Content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 3 Content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>