2011-12-26 2 views
0

Я начал в настоящее время портфельное приложение для планшета HoneyComb. Я использовал ActionBar.Tab для реализации трех вкладок в ActionBar и Fragment для каждой вкладки. Три названия вкладки «О программе», «Галерея», «Настройки». В Настройке ActionBar.Tab я хочу иметь TabHost. Это означает, что у вас есть вкладка внутри фрагмента. Спасибо заранее за ваши идеи !!!TabHost внутри фрагмента в HoenyComb

ответ

3

Есть макет с tabhost, как (если вы определить это как my_fragment_tabhost):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
    <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:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
      <TabWidget 
        android:id="@android:id/tabs" 
        android:visibility="gone" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/> 
      <FrameLayout 
        android:id="@android:id/tabcontent" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"/> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 

В вашем фрагменте, имеет переменный с членом TabHost и получить его в onCreateView как:

private TabHost mTabHost; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.my_fragment_tabhost, container, false); 
     mTabHost = (TabHost) view.findViewById(android.R.id.tabhost); 
     mTabHost.setup();//very important to call this 

     TabHost.TabSpec tab = mTabHost.newTabSpec("my tab content"); 
     tab.setIndicator("my tab content") 
//... add your content by one of the tab.setContent() methods 
     mTabHost.addTab(tab); 
     return view; 
    } 
+0

Вы только что спасли мою задницу с помощью этого mTabHost.setup(); Спасибо. –