简体   繁体   English

从片段替换片段

[英]replace a fragment from fragment

I have ActivityFragment with two Fragment i can start a fragement from the ActivityFragment using : 我有两个带有ActivityFragment的片段,我可以使用以下命令从ActivityFragment开始片段化:

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 我的问题是试图取代时MyFragment()由其他片段R.id.center_layoutMyFragment()

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() . 使用getFragmentManager()代替getChildFragmentManager() Also, if you want to replace the fragment, you should probably be using the replace method instead of add . 另外,如果要替换片段,则可能应该使用replace方法而不是add

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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