Magnus Johansson
Magnus Johansson

Reputation: 28325

Why can't my TabHost child activity find the parent TabHost ID?

I have a TabHost activity that are switching activities, so my main looks like this:

<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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dp" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-4dp"
            android:layout_weight="0" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp" />
    </LinearLayout>

</TabHost>

And one of my child activities XML is a ListView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </ListView>

</LinearLayout>

And in this child activity, (which extends ListActivity) I'm trying to find the parent TabHost:

TabHost tabHost = (TabHost) getParent().findViewById(R.id.tabhost);
tabHost.setCurrentTab(0);

But, the R.id.tabhost is not found (tabhost id cannot be resolved).
What am I doing wrong?

Upvotes: 2

Views: 2837

Answers (1)

Som
Som

Reputation: 1544

Make it android.R.id.tabhost It will work.

Upvotes: 3

Related Questions