0

我正在創建自定義tabhost,在每個選項卡規範中打開不同的活動。我想獲取標籤主機上的子活動,以在標籤主機屏幕上查找線性佈局。如何在Android的子活動中查找標籤主機?

select_item.xml(接頭主機配置)

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

<include 
    android:id="@+id/include1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    layout="@layout/outcom_actionbar" > 
</include> 

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

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="0.5dip" 
      android:background="#fff" /> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="0dip" 
      android:layout_marginRight="0dip" /> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dip" 
      android:background="#696969" /> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dip" 
      android:background="#add23b" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </LinearLayout> 
</TabHost> 

</LinearLayout> 

SelectItem.java(自定義選項卡主機)

public class SelectItem extends TabActivity { 

private TabHost mTabHost; 

private void setupTabHost() { 
    mTabHost = (TabHost) findViewById(android.R.id.tabhost); 
    mTabHost.setup(); 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.select_item); 
    context=this;  

    setupTabHost(); 
    mTabHost.getTabWidget().setDividerDrawable(null); 
    setupTab(new TextView(this), getString(R.string.Positions),Constants.ActivityName.Positions.toString()); 
    setupTab(new TextView(this), getString(R.string.Sever),Constants.ActivityName.Sever.toString()); 

} 

private void setupTab(final View view, final String tag,final String activityName) { 
    View tabview = createTabView(mTabHost.getContext(), tag); 

    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() { 
     public View createTabContent(String tag) {return view;} 
    }); 
    Intent intent =null; 
    if(activityName.compareToIgnoreCase(Constants.ActivityName.Positions.toString())==0)   
     intent = new Intent().setClass(this, Items.class); 
    else if(activityName.compareToIgnoreCase(Constants.ActivityName.Sever.toString())==0) 
     intent = new Intent().setClass(this, Sever.class);  
    intent.putExtra(Constants.PROJECT_ID, projectId); 
    setContent.setContent(intent); 
    mTabHost.addTab(setContent); 

} 

private static View createTabView(final Context context, final String text) { 
    View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null); 
    TextView tv = (TextView) view.findViewById(R.id.tabsText); 
    tv.setText(text); 
    return view; 
} 

} 

在服務器活動我想查看LinearLayoutselect_item.xml文件。但是我能夠在Sever活動中獲得標籤主機的詳細信息。

請建議我使用可用的鏈接或示例代碼。

回答

1

下面是一個可以幫助你的例子。 Click here 看看鏈接,並檢查他的項目在GitHub上。它真的幫助我。