Moja rozwijać środowisko jest Android Studio 0.8.9 z API19 SDK.
Jeśli umieści się FragmentTabHost w FragmentActivity, zadziała. Po umieszczeniu fragmentu FragmentTabHost w fragmencie, uzyskuje on "brak karty dla znacznika null" podczas renderowania i uzyskuje błąd runtime, gdy LayoutInflater nadyma układ.
Dziękuję za odpowiedź użytkownika3216049, jest to dobre rozwiązanie. Niestety, nie mogę głosować, ponieważ jestem początkującym. :(
Jednak wyświetli nic w moich badań fragmentów tab. zrobiłem małą modyfikację.
<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" />
- kod Java Chodzi o to, że mogę zmienić identyfikator z "R.id.realtabcontent" w FragmentTabHost.setup()
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;
}
}
}
Jakiego kodu używasz ? Czy używasz menu xml? Czy masz logcat? –
Czy mógłbyś opublikować kod, w którym zainicjowałeś TabHost? –
Otworzyłem raport o błędzie, zagłosuj na niego: https://code.google.com/p/android/issues/detail?id=78772 – Gavriel