简体   繁体   中英

replace a fragment from fragment

I have ActivityFragment with two Fragment i can start a fragement from the ActivityFragment using :

FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
transaction.add(R.id.center_layout, new MyFragment());
transaction.commit();

my problem is when trying to replace MyFragment() by an other Fragment in R.id.center_layout from MyFragment() class

i tried

FragmentTransaction transaction =this.getChildFragmentManager()
    .beginTransaction();
transaction.add(R.id.center_layout, client_Ajouter);
transaction.commit();

but i get

No view found for id 0x7f06000b (center_layout) for fragment Client_Ajouter

and thank you.

Use getFragmentManager() instead of getChildFragmentManager() . Also, if you want to replace the fragment, you should probably be using the replace method instead of add .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM