Reputation: 3
how to create multiple tabwidget in a tabhost, i get nullpointer exception when i do that
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1" />
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
Upvotes: 0
Views: 1023
Reputation: 515
To add multiple tabs you have to create tabSpec objects than add each tabspec using .addTab() method of TabbHost.
Example
myTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
myTabHost.setup(this,getsupportFragmentManager(),android.R.id.tabcontent);
myTabHost.addTab(myTabHost.newTabSpec("tab1").setIndicator("Tab1",null), SomeFragmentClass.class,null);
myTabHost.addTab(myTabHost.newTabSpec("tab2").setIndicator("Tab2",null), AnotherFragmentClass.class,null); // just pass fragment classes with it
I hop it will help...
Upvotes: 1
Reputation: 24667
You don't need that second TabWidget in there.
If you're asking about adding more than 1 tab to a TabHost see this tutorial: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
Check Step 6 carefully where a newTabSpec() is created.
Upvotes: 1