我有一个正在切换 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/