android - 为什么我的 TabHost 子 Activity 找不到父 TabHost ID?

标签 android android-tabhost

我有一个正在切换 Activity 的 TabHost Activity ,因此我的主要 Activity 如下所示:

<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>

我的子 Activity XML 之一是 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>

在这个子 Activity 中(它扩展了ListActivity),我试图找到父 TabHost:

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

但是,找不到 R.id.tabhost(tabhost id 无法解析)。
我做错了什么?

最佳答案

将其设为 android.R.id.tabhost 它会起作用的。

关于android - 为什么我的 TabHost 子 Activity 找不到父 TabHost ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9761266/

相关文章:

java - Android解压功能不起作用

Android - Activity 层次结构(后退按钮)

android - 如何在销毁创建周期之间保存 tabhost 选项卡

android - Android 中的选项卡无法正常工作?

java - Android TabView 错误?

android - 将 ListView 选定的项目保存在具有 ViewPager 的 fragment 中

android - 我可以在 Corona 中使用麦克风吗?

java - 使用 Android 上传文件时如何重命名文件?

android - 如何在 Tabhost 和 Activity 之间进行通信

Android 完成当前 Activity 并启动父 Activity