1. Download our Official Android App: Forums for Android!

Apps TabHost issue

Discussion in 'Android Development' started by math1100, Apr 5, 2011.

  1. math1100

    math1100 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Mar 28, 2011

    Mar 28, 2011
    3
    0
    5
    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:eek:rientation="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>
     

    Advertisement

  2. c0d3Black

    c0d3Black Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Apr 6, 2011

    Apr 6, 2011
    2
    0
    5
    Hi,

    Is it still not working?
     
  3. c0d3Black

    c0d3Black Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Apr 6, 2011

    Apr 6, 2011
    2
    0
    5
    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.
     
  4. tomsfacts

    tomsfacts Newbie
    Rank:
    None
    Points:
    16
    Posts:
    24
    Joined:
    Oct 20, 2010

    Oct 20, 2010
    24
    1
    16
    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.
     
  5. math1100

    math1100 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Mar 28, 2011

    Mar 28, 2011
    3
    0
    5
    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?
     

Share This Page

Loading...