meine Umgebung entwickeln Android Studio 0.8.9 mit API19 SDK ist.
Wenn ich das FragmentTabHost in eine FragmentActivity setze, funktioniert es. Wenn ich das FragmentTabHost in ein Fragment einfüge, erhält es beim Rendern "keinen Tab, der für Tag null bekannt ist" und erhält Laufzeitfehler, wenn LayoutInflater das Layout aufbläst.
Danke für user3216049's Antwort, es ist eine gute Problemumgehung. Sorry, ich kann nicht wählen, da ich ein Neuling bin. :(
aber es ist nichts in meinem Test Tab Fragmente anzuzeigen. habe ich eine kleine Änderung.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
</LinearLayout>
- fragment_section_dummy.
xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="24sp"
android:padding="32dp" />
- Java-Code Der Punkt ist, dass ich die ID der "R.id.realtabcontent" in FragmentTabHost.setup ändern()
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
public class TestFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
FragmentTabHost tabHost = new FragmentTabHost(getActivity());
inflater.inflate(R.layout.test_fragment, tabHost);
tabHost.setup(getActivity(),
getChildFragmentManager(), R.id.realtabcontent);
tabHost.addTab(tabHost.newTabSpec("simple")
.setIndicator("Simple"), DummySectionFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("contacts")
.setIndicator("Contacts"), DummySectionFragment.class, null);
return tabHost;
}
/**
* A dummy fragment representing a section of the app,
* but that simply displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
private static int count = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section_dummy,
container, false);
((TextView) rootView.findViewById(android.R.id.text1))
.setText("Dummy Section " + count++);
return rootView;
}
}
}
Welchen Code verwenden Sie ? Verwenden Sie ein Menü-XML? Hast du einen Logcat? –
Können Sie den Code, in dem Sie den TabHost initialisieren, posten? –
Ich habe einen Fehlerbericht geöffnet, bitte abstimmen: https://code.google.com/p/android/issues/detail?id=78772 – Gavriel