2012-03-06 46 views
0

當選項卡更改時,將活動X加載到FrameLayout中時,我希望該X能夠訪問位於TabHost之外的tmp LinearLayout。 假設TmpActivity裝入FrameLayout裏被點擊了一些標籤的時候,所以在這個活動我想要做這樣的事如何訪問位於TabHost的FrameLayout之外的視圖?

public void onCreate(Bundle savedInstanceState) { 
     LinearLayout ll = (LinearLayout)findViewById(R.id.tmp);    
    } 

我怎樣才能做到這一點?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <LinearLayout 
       android:id="@+id/tmp" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="50px" 
       android:background="#00FF00">    
     </LinearLayout> 

     <TabHost 
      android:id="@android:id/tabhost" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:padding="5dp"> 

       <FrameLayout 
        android:id="@android:id/tabcontent" 
        android:layout_width="fill_parent" 
        android:layout_height="500px" 
        android:padding="5dp" 
        android:background="#FF0000"/> 
       <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="#FF00FF" /> 
      </LinearLayout> 
     </TabHost> 
</LinearLayout> 

回答

0

您可以從您的標籤主機框架佈局中加載的活動中獲得您的父級活動。從那裏,您可以通過位於TabHostActivity中的getter或成員變量來訪問線性佈局。

相關問題