40

Układ graficzny dla prostego android.support.v4.app.FragmentTabHost nigdy nie renderuje się w Eclipse lub Android Studio.
błąd Konsola mogę to konsekwentnie:
Exception raised during rendering: No tab known for tag nullUkład graficzny FragmentTabHost nie renderuje

używam najbardziej podstawowego pliku XML:

<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <TabWidget 
      android:id="@android:id/tabs" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 

    </LinearLayout> 
</android.support.v4.app.FragmentTabHost> 

ale pojawia się ten sam błąd.

Po prostu chciałem dodać więcej widoków powyżej lub poniżej widgetu karty i układu ramki.
Nie przejmuję się zbytnio widzeniem zawartości karty; Chcę po prostu zobaczyć resztę mojego układu - ale problemem jest to, że żadne inne widoki są renderowane, gdyandroid.support.v4.app.FragmentTabHosttkwi w układzie.

Czytałem i starał się rozwiązać problem z odpowiedzią na to stanowisko:
Android: Tabs at the bottom with FragmentTabHost
ale nie sądzę, że to jest mój problem; Nie chcę umieścić TabWidget na dole.

Każdy inny mój plik XML otwiera się idealnie.

Ten sam problem pojawia się w Android Studio:
Android Studio doesn't render this either

+0

Czy to logcat lub konsola? Jeśli logcat, opublikuj. – anthropomo

+0

to jest dziennik błędów: w eclipse: (Wyjątek wywoływany podczas renderowania: brak zakładki dla znacznika null Szczegóły wyjątku są rejestrowane w oknie> Pokaż widok> Dziennik błędów) – lory105

+3

FragmentTabHost nie będzie wyświetlał żadnych treści, ponieważ zawartość zostanie dodana dynamicznie . Więc nie ma problemów. Powinien działać, gdy dodasz karty w kodzie i przetestujesz je. http://www.androidhive.info/2011/08/android-tab-layout-tutorial/ – mipreamble

Odpowiedz

0

nie wiesz .... ale nie powinien mieć Twój układ tag tabhost w nim powyżej układ liniowej tabwidget za?

<TabHost 
    android:id="@+id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
> 

zrobiłem aplikację jakiś czas temu, że implented zakładki za pomocą tabhost i to jest jak mój układ był ... jedna karta miał widok kalendarza jeden miał przełącznik obrazu i jeden miał ListView ... przykro mi nie może być więcej pomocy

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
tools:context=".MainActivity" > 

<TabHost 
    android:id="@+id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/background" 
     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" > 

      <LinearLayout 
       android:id="@+id/tab1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ListView 
        android:id="@+id/listView1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </ListView> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/tab2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ImageSwitcher 
        android:id="@+id/imageSwitcher1" 
        android:layout_width="match_parent" 
        android:layout_height="251dp" > 
       </ImageSwitcher> 

       <TextView 
        android:id="@+id/tv" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:scrollbars="vertical" /> 

      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/tab3" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <CalendarView 
        android:id="@+id/calendarView1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
      </LinearLayout> 

     </FrameLayout> 
    </LinearLayout> 

</TabHost> 

+2

Cóż, zwykły android.widget.TabHost będzie działał, z wyjątkiem tego, że [android.app.TabActivity jest przestarzałe] [tabactivity] na rzecz używania FragmentTabHosts i Fragments. [tabactivity]: [http://developer.android.com/reference/android/app/TabActivity.html] – EricRobertBrewer

1

nie jestem pewien co do błędu już dostał (przepraszam, jestem bardzo zajęty w tej chwili, więc nie mogę poświęcić więcej czasu na sprawdzenie), ale w ogóle wydaje się, że FragmentTabHost z bibliotek wsparcia nie obchodzi w ogóle xml. Patrz mój poprzedni odpowiedź na inne pytanie:

FragmentTabHost with horizontal scroll

1

z układu otrzymuję ten sam Error..so, mam rozwiązać ten problem przez Kodeksu tylko ... To działa fine..Please wypróbować ten kod

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTabHost; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

public class DetailFragment extends Fragment { 

    /****************************************************************************************************************** 
    * Mandatory empty constructor for the fragment manager to instantiate the fragment (e.g. upon screen orientation changes). 
    *****************************************************************************************************************/ 
    public DetailFragment() { 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     // R.layout.fragment_tabs_pager contains the layout as specified in your question 
     View rootView = inflater.inflate(R.layout.fragment_tabs_pager, container, false); 

     // Initialise the tab-host 
     FragmentTabHost mTabHost = (FragmentTabHost) rootView.findViewById(R.id.tabhost); 
     mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); 

     // Initialise this list somewhere with the content that should be displayed 
     List<String> itemsToBeDisplayed; 

     for (String subItem : itemsToBeDisplayed) { 
      // Give along the name - you can use this to hand over an ID for example 
      Bundle b = new Bundle(); 
      b.putString("TAB_ITEM_NAME", subItem); 

      // Add a tab to the tabHost 
      mTabHost.addTab(mTabHost.newTabSpec(subItem).setIndicator(subItem), YourContentFragment.class, b); 
     } 
     return rootView; 
    } 
} 



/******************************************************** 
This class contains the actual content of a single tab 
**********************************************************/ 
public class YourContentFragment extends Fragment { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     Bundle extras = getArguments(); 
     if (extras != null) { 
      if (extras.containsKey("TAB_ITEM_NAME")) { 
       String subItem = extras.getString("TAB_ITEM_NAME"); 
       // Do something with that string 
      } 
     } 
    } 
} 
1

Jeśli u trzeba umieścić pofragmentowane kart na dole ekranu ... @fallow niżej -

Dodać plik xml tak ..

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

     <!-- <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> android:layout_alignParentTop="true" --> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" /> 


     <android.support.v4.app.FragmentTabHost 
      android:id="@android:id/tabhost" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      > 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="0dip" 
       android:layout_height="0dip" 
       android:layout_weight="0" /> 

     </android.support.v4.app.FragmentTabHost> 

    </LinearLayout> 

Teraz jeśli twoim problemem jest otwarcie kilku fragmentów z rozdrobnionych w pojedynczych kartach ...

@follow kroki ::

  1. Załóż fragment pojemnika. Ten fragment kontenera będzie domyślny dla wszystkich zawartości twoich kart.
  2. Dla każdej zawartości karty zastąp fragment U potrzebny z tym kontenerem.

Dla ex: - Podobnie jak zamienić swoje łóżko z różnych pościeli .. :)

Kontener klasa fragment, który będzie używany w różny sposób w różnych zakładkach ... „LearnContainerFragment.java”

public class LearnContainerFragment extends BaseContainerFragment { 

     private boolean mIsViewInited; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
      Log.e("test", "tab 1 oncreateview"); 
      return inflater.inflate(R.layout.container_fragment, null); 
     } 

     @Override 
     public void onActivityCreated(Bundle savedInstanceState) { 
      super.onActivityCreated(savedInstanceState); 
      Log.e("test", "tab 1 container on activity created"); 
      if (!mIsViewInited) { 
       mIsViewInited = true; 
       initView(); 
      } 
     } 

     private void initView() { 
      Log.e("test", "tab 1 init view"); 
      replaceFragment(new Learn(), false); 
     } 

    } 

LearnContainerFragment.java ---> to plik XML container_fragment.xml

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/container_framelayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


    </FrameLayout> 

@ Jak korzystać Cona tiner ..

  1. Dla każdego fragmentu U potrzeba będzie zastąpiony identyfikatorem tego fragmentu kontenera.

@Last swojej klasie BaseContainerFragment.java -

public class BaseContainerFragment extends Fragment { 

    public void replaceFragment(Fragment fragment, boolean addToBackStack) { 
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 
     if (addToBackStack) { 
      transaction.addToBackStack(null); 
     } 
     transaction.replace(R.id.container_framelayout, fragment); 
     transaction.commit(); 
     getChildFragmentManager().executePendingTransactions(); 
    } 

    public boolean popFragment() { 
     Log.e("test", "pop fragment: " + getChildFragmentManager().getBackStackEntryCount()); 
     boolean isPop = false; 
     if (getChildFragmentManager().getBackStackEntryCount() > 0) { 
      isPop = true; 
      getChildFragmentManager().popBackStack(); 
     } 
     return isPop; 
    } 

} 

Nadzieja to pomaga ..... Cheers!

4

Miałem ten sam problem z renderowaniem, jak również błąd kompilacji. Rozwiązałem problem, stwierdzając, że nie przekazałem Fragmentu podczas tworzenia Addtabu. Musisz minąć co najmniej jeden fragment na mTabHost.addTab. Poniżej znajduje się działający kod.

private FragmentTabHost mTabHost; 
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
      mTabHost.setup(HomeActivity.this, getSupportFragmentManager(), android.R.id.tabcontent); 

      mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("Home"), HomeFragment.class, null); 
      mTabHost.addTab(mTabHost.newTabSpec("mysheets").setIndicator("MySheets")); 
      mTabHost.addTab(mTabHost.newTabSpec("bookmarks").setIndicator("Bookmarks"));