I'm currently trying to include 2 Fragments inside a Viewpager Fragment. All works fine, but if I scroll 2 Fragments further and return to the one with the two fragments only the upper one is visible(Fragment B is invisible). If i do this again both are visible again. The onResume-Event is called in Fragment B but it is not shown. Layout XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/a_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/android_color_blue_dark"/>
<FrameLayout
android:id="@+id/b_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/android_color_green_dark" />
</LinearLayout>
Parent Fragment Code in onCreateView()
if (v.findViewById(R.id.a_fragment) != null) {
FragmentManager mgr = getChildFragmentManager();
Fragment f = mgr.findFragmentByTag(TAG_A_FRAGMENT);
if (f == null) {
f = new FragmentA();
}
FragmentTransaction transaction = mgr.beginTransaction();
transaction.replace(R.id.a_fragment, f, TAG_S_FRAGMENT);
transaction.commit();
}
if (v.findViewById(R.id.b_fragment) != null) {
FragmentManager mgr = getChildFragmentManager();
Fragment f = mgr.findFragmentByTag(TAG_B_FRAGMENT);
if (f == null) {
f = new FragmentBLogin();
}
FragmentTransaction transaction = mgr.beginTransaction();
transaction.replace(R.id.b_fragment, f,
TAG_B_FRAGMENT);
transaction.commit();
}
I do add those Fragments dynamically even if they are static to prevent this Error.