Das grafische Layout für ein einfaches Android.support.v4.app.FragmentTabHost wird weder in Eclipse noch in Android Studio dargestellt.
Der Konsolenfehler, den ich erhalte, ist konsistent:Exception raised during rendering: No tab known for tag null
Ich verwende die grundlegendste XML-Datei:
<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>
aber der gleiche Fehler tritt auf.
Ich wollte nur mehr Ansichten über oder unter dem Tab-Widget und dem Rahmenlayout hinzufügen.
.__ Es interessiert mich nicht so sehr, den Tab-Inhalt zu sehen. Ich möchte nur den Rest meines Layouts - sehen, aber das Problem ist, dass KEINE ANDEREN ANSICHTEN gerendert werden, wenn sich einAndroid.support.v4.app.FragmentTabHost
im Layout befindet.
Ich habe gelesen und habe versucht, das Problem aus der Antwort auf diesen Beitrag zu lösen:
Android: Tabs unten mit FragmentTabHost
aber ich glaube nicht, dass das mein problem ist; Ich schaue nicht nach einem TabWidget auf der Unterseite.
Jede zweite meiner XML-Dateien wird perfekt geöffnet.
Das gleiche Problem tritt in Android Studio auf:
Ich hatte das gleiche Rendering-Problem sowie Kompilierungsfehler. Ich habe das Problem behoben, indem ich herausfand, dass ich Fragment nicht übergeben habe, als ich Addtab erstellt habe. Sie müssen mindestens ein Fragment in mTabHost.addTab übergeben. Unten ist der Arbeitscode.
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"));
Ich bin mir nicht sicher, was für einen Fehler Sie haben (Entschuldigung, ich bin momentan sehr beschäftigt, kann also nicht mehr Zeit damit verbringen, zu prüfen), aber im Allgemeinen scheint es, dass die FragmentTabHost
von den Unterstützungsbibliotheken die XML überhaupt nicht interessiert. Siehe meine vorherige Antwort auf eine andere Frage:
Von Layout bekomme ich den gleichen Fehler ... also löse ich das Problem nur durch Code ... Es funktioniert gut .. Bitte versuchen Sie diesen Code
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
}
}
}
}
Wenn Sie fragmentierte Registerkarten am unteren Rand des Bildschirms einfügen müssen ... @ Brachliegend -
Machen Sie Ihre XML-Datei so ..
<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>
Wenn Ihr Anliegen nun mehrere Fragmente mit einzelnen, fragmentierten Registerkarten öffnet ...
@Folgen Sie Schritte ::
Zum Beispiel: - So wie Sie Ihr Bett durch verschiedene Bettlaken ersetzen .. :)
Ihre Container-Fragment-Klasse, die auf verschiedenen Registerkarten unterschiedlich verwendet wird ... "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 ---> ist die XML-Datei 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>
@ Wie benutze ich Conatiner?.
@Last Ihrer BaseContainerFragment.Java-Klasse -
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;
}
}
Ich hoffe es hilft..... Prost!
nicht sicher ... aber sollte Ihr Layout nicht über dem linearen Layout von tabwidget ein Tabhost-Tag enthalten?
<TabHost
Android:id="@+id/tabhost"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:background="@drawable/background"
>
ich habe vor einiger Zeit eine App erstellt, die Tabs mit Tabhost implizierte, und so war mein Layout ... Ein Tab hatte eine Kalenderansicht, ein Bildwechsler und einer hatte eine Listenansicht ... Entschuldigung, ich kann nicht mehr helfen
<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>