Search code examples
androidandroid-emulatorandroid-tabhostandroid-tabactivity

Android tab layout error


I created an app with 2 tabs using TabLayout...

I need to integrate that application with another application.But while i reach the tab page,its ending up with an error

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android/com.android.simphone.SimFoneDetailsActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

I changed the id of the TabHost,but no use......Please any suggestions are welcome...

The xml portion of the code is also attached...

<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" 
android:background="@drawable/bg_sim">
<LinearLayout 
android:id="@+id/LinearLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget 
android:id="@+id/tabs" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"></TabWidget>
<FrameLayout 
android:id="@+id/tabcontent" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"></FrameLayout>
</LinearLayout>
</TabHost>

Solution

  • try 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" 
    android:background="@drawable/bg_sim">
    <LinearLayout 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <TabWidget 
    android:id="@android:id/tabs" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"></TabWidget>
    <FrameLayout 
    android:id="@android:id/tabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"></FrameLayout>
    </LinearLayout>
    </TabHost>
    

    Note that for tabs to work correctly you need to use this @android:id/