2012-03-18 12 views
2

このような私の主なルックスので、私は、活動を切り替えているTabHost活性を有する:私のTabHost子アクティビティで親TabHost IDを見つけることができないのはなぜですか?

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

そして、私の子アクティビティのXMLの一つは、リストビューです:

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

そしてこの子アクティビティでは、(

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

しかし、R.id.tabhostが発見されていない:私は親TabHostを見つけようとしている(これはListActivityを拡張します) 0)。
何が間違っていますか?

+0

おそらく1つ以上の親があります。あなたは[階層ビューア](http://developer.android.com/guide/developing/tools/hierarchy-viewer.html)でそれを見つけようとすることもできます。これは、Eclipseに組み込まれています – zapl

答えて

3

にするandroid.R.id.tabhost これは動作します。

+0

はい!私はちょうどXML ID宣言のアンドロイドプレフィックスについて考えていた。そして確かに、それは動作します、ありがとう。 –

+0

ありがとうございました。 –

関連する問題