40

एक साधारण android.support.v4.app.FragmentTabHost के लिए ग्राफ़िकल लेआउट या तो ग्रहण या एंड्रॉइड स्टूडियो में कभी प्रस्तुत नहीं करता है।
कंसोल त्रुटि मैं लगातार है:
Exception raised during rendering: No tab known for tag nullFragmentTabHost ग्राफ़िकल लेआउट

मैं सबसे बुनियादी एक्सएमएल फ़ाइल उपयोग कर रहा हूँ:

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

लेकिन एक ही त्रुटि तब होती है।

मैं बस टैब विजेट और फ्रेम लेआउट के ऊपर या नीचे अधिक दृश्य जोड़ना चाहता था।
मुझे टैब सामग्री देखने के बारे में बहुत परवाह नहीं है; मैं सिर्फ को अपना बाकी लेआउट - देखना चाहता हूं लेकिन समस्या यह है कि कोई अन्य दृश्य प्रस्तुत नहीं किया जाता है जबandroid.support.v4.app.FragmentTabHostलेआउट में रहता है।

मैंने पढ़ा है और इस पोस्ट का जवाब से समस्या को हल करने की कोशिश की है:
Android: Tabs at the bottom with FragmentTabHost
लेकिन मुझे नहीं लगता है कि मेरी समस्या है; मैं नीचे एक TabWidget डालने की तलाश नहीं कर रहा हूँ।

मेरी एक्सएमएल फाइलों में से प्रत्येक एक पूरी तरह से खुलता है।

एक ही समस्या एंड्रॉयड स्टूडियो में होता है:
Android Studio doesn't render this either

+0

क्या यह त्रुटि लॉगक या कंसोल है? अगर लॉगकैट, कृपया पोस्ट करें। – anthropomo

+0

यह एक त्रुटि लॉग है: ग्रहण: (प्रतिपादन के दौरान उठाए गए अपवाद: टैग नल के लिए ज्ञात कोई भी टैब विंडो में लॉग इन नहीं है> दृश्य दिखाएँ> त्रुटि लॉग) – lory105

+3

FragmentTabHost कोई सामग्री नहीं दिखाएगा क्योंकि सामग्री को गतिशील रूप से जोड़ा जाएगा । तो कोई समस्या नहीं है। जब आप कोड में टैब जोड़ते हैं और इसका परीक्षण करते हैं तो काम करना चाहिए। http://www.androidhive.info/2011/08/android-tab-layout-tutorial/ – mipreamble

उत्तर

0

यकीन नहीं .... नहीं बल्कि अपने लेआउट tabwidget के रेखीय लेआउट ऊपर उस में एक tabhost टैग होना चाहिए?

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

मैं समय पहले कि tabhost का उपयोग करके टैब implented कोई ऐप्लिकेशन एक बना दिया है और यह कैसे मेरी लेआउट था है ... एक टैब एक कैलेंडर दृश्य एक एक छवि स्विचर था और एक सूचीदृश्य था ... खेद है कि मैं था और अधिक मदद की नहीं किया जा सकता

<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

ठीक है, एक नियमित android.widget.TabHost काम करेगा, सिवाय इसके कि [android.app.TabActivity बहिष्कृत है] [tabactivity] FragmentTabHosts और Fragments का उपयोग करने के पक्ष में। [Tabactivity]: [http://developer.android.com/reference/android/app/TabActivity.html] – EricRobertBrewer

1

त्रुटि आप मिल गया है के बारे में सुनिश्चित नहीं हैं (क्षमा करें, मैं अभी वास्तव में व्यस्त हूँ तो जाँच अधिक समय खर्च नहीं कर सकते हैं), लेकिन सामान्य रूप में यह ऐसा लगता है कि समर्थन libs से FragmentTabHost एक्सएमएल के बारे में परवाह नहीं करता है। एक और सवाल करने के लिए अपने पिछले जवाब देखें:

FragmentTabHost with horizontal scroll

1

लेआउट मैं एक ही Error..so हो रही है से, मैं कोड द्वारा कि समस्या का समाधान केवल ... यह fine..Please इस कोड की कोशिश काम कर रहा है

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

यू स्क्रीन के नीचे खंडित टैब डाल करने के लिए की जरूरत है ... @fallow नीचे लिखा हुआ -

इस तरह अपने xml फ़ाइल बनाने ..

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

अब यदि आपकी चिंता एकल खंडित टैब में कई टुकड़े खोल रही है ...

@follow चरणों ::

  1. एक कंटेनर टुकड़ा बनाएँ। यह कंटेनर खंड आपके सभी टैब सामग्री के लिए डिफ़ॉल्ट होगा।
  2. प्रत्येक टैब सामग्री के लिए इस कंटेनर के साथ खंड यू की आवश्यकता है।
पूर्व के लिए

: - वैसे ही जैसे आप विभिन्न चादरें के साथ अपने बिस्तर की जगह .. :)

आपका कंटेनर टुकड़ा वर्ग है कि विभिन्न टैब में अलग ढंग से उपयोग किया जाएगा ... "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 ---> यह 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> 

@ कैसे Cona उपयोग करने के लिए tiner ..

  1. प्रत्येक टुकड़े के लिए यू की आवश्यकता इस कंटेनर खंड की आईडी के साथ प्रतिस्थापित की जाएगी।

अपने BaseContainerFragment.java वर्ग @last -

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; 
    } 

} 

आशा है कि यह मदद करता है ..... चीयर्स!

4

मेरे पास समान प्रतिपादन समस्या के साथ-साथ संकलन त्रुटि भी थी। मैंने यह पता लगाकर समस्या को ठीक किया कि जब मैं Addtab बना रहा था तो मैं फ्रैगमेंट पास नहीं कर रहा था। आपको mTabHost.addTab पर कम से कम एक टुकड़ा पारित करना होगा। नीचे काम कोड है।

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