• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps TabHost issue

math1100

Lurker
I cannot get a TabHost to work on my emulator. I am trying to use sample code from the android developers website, but every time I run the activity containing the code, I get a forced close error. The code I used is below. Anyone know what the deal is?

<?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="fill_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
 
I setup my tabs in code, not in the layout.

Something in the lines of this
-------------------------------------------------------
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, TabJobCategory.class);
spec = tabHost.newTabSpec("tabone").setIndicator("Browse",
getResources().getDrawable(R.drawable.ic_tab_browse_selected)).setContent(intent);
tabHost.addTab(spec);

tabHost.setCurrentTab(tabHost.getChildCount()-1);


Also, in the layout for the tabs, dont include anything in the Frame Layout, rather make separate layout xmls per tab in the tab host. then you have batter partition the tabs.
 
Sometimes tabhost is glitchy and doesn't work properly. I have a set of code that works great on my device, but the tabhost doesn't work on the emu.
 
Even if I could get it working in code, I'm trying to figure out why it doesn't work in xml. I got the code from the android developer website. I even copied and pasted it into my xml layout file. I guess it might be that it doesn't work in the emulator?
 
Back
Top Bottom