Android ajouter Fragment Fragment à l'intérieur

Salut à tous (et merci à l'avance),

J'ai une application avec un Google Play Store-comme la mise en page (à l'aide de PagerTabStrip avec 5 sous-fragments). Dans certains de ces fragments, j'ai besoin d'afficher un peu d'info concernant la dernière fois que les données ont été mises à jour.

J'ai immédiatement pensé à la création d'un fragment (LastUpdatedFragment) qui, je puis ajouter (nid) pour les fragments dont j'avais besoin. Au premier abord, et depuis la dernière date de mise à jour qui était censé être le même pour chaque écran, les choses étaient de travail (j'ai simplement ajouté le fragment dans le xml de la société mère Fragments dont j'avais besoin et à l'intérieur de onCreateView je voudrais mettre la date dans le TextView), mais après quelques modifications que j'ai maintenant besoin d'envoyer une date précise pour chacun de ces LastUpdatedFragment instances.

Je suis venu avec un moyen de créer de nouveaux attributs personnalisés pour mon Fragment, puis je régler la date que je voulais. Après un peu de lecture, je suis tombé sur un moyen plus facile (Les Fragments à l'intérieur des Fragments - dinamically l'ajout du fragment à l'aide de FragmentManager) - je tout simplement besoin du parent Fragment de gérer les paramètres d'entrée et de transmettre à l'enfant fragment.

Le problème est que, bien que je n'obtiens pas d'erreurs, je reçois aussi pas d'enfant fragment, il ne vient pas de l'écran. Je vous serais reconnaissant si vous pouviez me guider dans la bonne direction.

ScoreBoardFragment.java -> Parent Fragment

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        rootView = inflater.inflate(R.layout.fragment_scoreboard, container,
                false);

        for (int i = 0; i < tvCount; i++) {
            tvName = "f_scoreboard_header_tv" + String.valueOf(i);
            resID = getResources().getIdentifier(tvName, "id",
                    _activity.getPackageName());
            header = (TextView) rootView.findViewById(resID);
            header.setTypeface(MyGlobalConfig.getInstance().getHeadersFont());
        }

        FragmentManager childFragMan = getChildFragmentManager();
        FragmentTransaction childFragTrans = childFragMan.beginTransaction();
        LastUpdatedFragment fragB = new LastUpdatedFragment();
        childFragTrans.add(R.id.FRAGMENT_PLACEHOLDER, fragB);
        childFragTrans.addToBackStack("B");
        childFragTrans.commit();        


        return rootView;
    }

fragment_scoreboard.xml (simplifié mais l'affichage de tout le reste)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/FRAGMENT_PLACEHOLDER"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            style="@style/ListView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/f_scoreboard_header_tv0"
                style="@style/ListViewRowHeader"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="#" />

        </LinearLayout>

        <ListView
            android:id="@+id/f_scoreboard_lvbody"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true" >
        </ListView>

    </LinearLayout>

LastUpdatedFragment.java -> Enfant Fragment

        public class LastUpdatedFragment extends Fragment{
        private View rootView;
        private TextView tv;
        private Context ctx;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(
                    getActivity()));
            this.ctx = getActivity().getApplicationContext();

        }

        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

            rootView = inflater.inflate(R.layout.fragment_date, container,
                    false);
            tv = (TextView) rootView.findViewById(R.id.f_date_tv);
            tv.setTypeface(MyGlobalConfig.getInstance().getBodyFont());
            tv.setText(getString(R.string.lastupdated) + ": " + Util.getLastUpdated(ctx));
            return rootView;
        }
    }

fragment_date.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/f_date_tv"
            style="@style/LastUpdatedTV"
            android:layout_width="match_parent"
            android:text="Data de última actualização: 27/12/2014 21:30" />
    </LinearLayout>
où est FRAGMENT_PLACEHOLDER déclaré ?
dans le fragment_scoreboard.xml -> c'est l'id de la première LinearLayout
Essayez d'utiliser FrameLayout au lieu de LinearLayout comme un espace Réservé.
où avez-vous ajouter ScoreBoardFragment?
que fait! Inscrivez votre réponse et je vais l'accepter ;). Merci à vous deux

OriginalL'auteur Bernardo | 2015-01-06