2012-03-06 15 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或成员变量来访问线性布局。

相关问题