Search code examples
androidandroid-layoutlayoutandroid-tabhost

TabWidget will not display, even though it displays in ADT editor


My TabWidget will not display, even though it shows up in the Eclipse graphical editor. I can't find any reason why. Why isn't my tab bar showing?

Eclipse

Imgur

Emulator

Imgur

XML source of the activity: http://pastebin.com/Au9XFXPa

Extract from activity:

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

Results from Android lint:

$ lint.bat res/layout/activity_calculator.xml
Scanning Catalyst: .
No issues found.

Solution

  • It's hard to tell without actual code of how your activity is implemented, but seems like you need to call setContent() on your TabHost:

        TabHost tabs = (TabHost)findViewById(R.id.tabhost);
        tabs.setup();
    
        // Calculator
        TabHost.TabSpec calculatorTab = tabs.newTabSpec("calculator");
        calculatorTab.setContent(R.id.calculator);
        calculatorTab.setIndicator("Calculator");
        tabs.addTab(calculatorTab);
    
        // Home
        TabHost.TabSpec homeTab = tabs.newTabSpec("home");
        homeTab.setContent(R.id.home);
        tabs.addTab(homeTab);
    
        // Home
        TabHost.TabSpec faqTab = tabs.newTabSpec("faq");
        faqTab.setContent(R.id.faq);
        tabs.addTab(faqTab);
    

    This should give you the idea.