2017-02-15 4 views
2

salutations mes collègues développeurs. je travaille sur un projet android dans lequel je suis en utilisant TabHost et à l'intérieur 2ème onglet je veux utiliser un autre TabHost, jusqu'à présent j'ai accompli ce mon principal XML TabHost estAndroid TabHost à l'intérieur de l'onglet TabHost

<TabHost 
    android:id="@+id/homeTabHost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <!--first tab content--> 
       <include layout="@layout/content_blood_glucose_diary_home" /> 

       <!--second tab content--> 
       <include layout="@layout/content_blood_glucose_diary_summary" /> 

       <!--3rd tab content--> 
       <include layout="@layout/content_blood_glucose_diary_activities" /> 

      </FrameLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"></TabWidget> 
     </LinearLayout> 
    </LinearLayout> 
</TabHost> 

et mon code java pour c'est

private void loadTabs(int tabhost, String tab1, String tab2, String tab3){ 
    TabHost host = (TabHost)findViewById(tabhost); 
    host.setup(); 

    loadTab(host, R.id.homeTab1, tab1); //tab 1 

    loadTab(host, R.id.homeTab2, tab2); //tab 2 

    loadTab(host, R.id.homeTab3, tab3); //tab 3 
} 

private void loadTab(TabHost host, int tabid, String tab){ 
    TabHost.TabSpec spec = host.newTabSpec(tab); 
    spec.setContent(tabid); 
    spec.setIndicator(tab); 
    host.addTab(spec); 
} 

que je fais appel à mon onCreate

loadTabs(R.id.homeTabHost, "Today", "Summary", "Activity"); 

jusqu'à à ce point les choses fonctionnent greate mais quand ajouter un autre tabhost dans mon xml sommaire (comme ceci)

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:weightSum="1"> 

    <TabHost 
     android:id="@+id/summaryTabHost" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.8"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"></TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <!--first tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab1" /> 
       </LinearLayout> 

       <!--second tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab2" /> 
       </LinearLayout> 

       <!--3rd tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab3" /> 
       </LinearLayout> 

       <!--4th tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab4" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab4" /> 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 

et dans mon fichier java i ajouter

private void loadTabs(int tabhost, String tab1, String tab2, String tab3, String tab4){ 
    TabHost host = (TabHost)findViewById(tabhost); 
    host.setup(); 

    loadTab(host, R.id.summaryTab1, tab1); //tab 1 

    loadTab(host, R.id.summaryTab2, tab2); //tab 2 

    loadTab(host, R.id.summaryTab3, tab3); //tab 3 

    loadTab(host, R.id.summaryTab4, tab4); //tab 4 
} 

dans ma fonction oncreate qui est

loadTabs(R.id.summaryTabHost, "All", "Yearly", "Monthly", "Weekly"); 

cela devrait fonctionner ... parce que c'est le même que le premier onglet hôte un .. premiers tabs tabhost ne montrent pas yup ..

mais quand je commente 2ème tabhost à l'intérieur du résumé xml .. les choses semblent normales. Mon diagnostic jusqu'à présent est que quelque chose ne va probablement pas bien avec 2nd TabHost.

des idées ce qui pourrait être mauvais ici ??? toute aide est reconnue !!

+0

dans cet exemple ... j'ai créé tabhost au bas de l'écran, mais si je le fais en haut de l'écran les deux tabhosts fonctionnent très bien .. il fonctionne aussi bien si je crée le premier tabhost haut de l'écran et le bas tabhost intérieur de l'écran il fonctionne aussi .. il semble premier tabhost ne disparaît que lorsque j'essaie de fais comme je l'ai fait en question –

Répondre

0

TabHost est Depriected vous pouvez utiliser tablayout si vous voulez faire des onglets à l'intérieur de l'onglet vous pouvez facilement l'utiliser dans le fragment interne

Androidhive tablayout tutorial