Un fragment imbriqué n'apparaît pas dans un ViewPager
La photo ci-jointe montre une ViewPager avec 3 pages. Chaque page est implémentée en tant que fragment. La barre d'outils comporte une icône + en noir pour l'ajout d'un nouveau patient. Lorsque l'icône + est pressée, un fragment imbriqué doit être créé dans la page Patients, ce qui permet la création d'un nouveau patient.
Dans Logcat, je peux voir que les rappels du cycle de vie des fragments pour le fragment imbriqué sont appelés jusqu'à onResume()
, mais la vue du fragment imbriqué n'est pas restituée.
Je fais cela pour créer le fragment imbriqué et l'insérer dans la hiérarchie de vue fragment parent:
FrPatientDetails frChild = new FrPatientDetails();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction()
.replace(R.id.flPatientsPage, frChild);
transaction.addToBackStack(null)
.commit();
R.id.flPatientsPage
est un FrameLayout
dans la page Les patients où je suis en train d'insérer le fragment imbriqué. J'ai l'impression que la façon d'insérer un fragment enfant dans un fragment parent hébergé dans un ViewPager
peut être différente, mais je ne sais pas quoi faire.
Quelqu'un pourrait-il aider ici?
Mise à jour: Ajout de la xml pour la page Patients (parent)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/patients_page_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lvHomeViewPatientsPage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/colorPrimary"
android:dividerHeight="1dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/tvEmpty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@android:color/black"
android:text="@string/patients_page_empty"
android:fontFamily="sans-serif"
android:gravity="center"
android:textSize="16sp"
/>
<FrameLayout
android:id="@+id/flPatientsPage"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Mise à jour: Voici la capture d'écran après avoir suivi ce @Filo suggéré:
Avez-vous essayé avec 'add' au lieu de' replace'? – Fllo
Oui. J'ai essayé 'add' et' repalce' et les deux donnent le même résultat. – Amit
le signe plus ajoute un fragment imbriqué en rapport avec le fragment affiché –