2016-11-14 73 views

回答

1

一个Fragment属于主机Activity,而不是反过来。 Activity可以承载多个Fragment

读取更多的信息文档: https://developer.android.com/guide/components/fragments.html

你的情况,似乎什么你想实现的是一个不同的布局和逻辑来代替Form Transaction Fragment。您可以将其替换为另一个新的Fragment本身。

使用FragmentManager替换现有Fragment

FragmentManager fm = getFragmentManager(); 

if (fm != null) { 
    // Perform the FragmentTransaction to replace the Form Transaction content. 
    // Using FragmentTransaction#replace will destroy any Fragments 
    // currently inside R.id.fragment_content and add the new Fragment 
    // in its place. 
    FragmentTransaction ft = fm.beginTransaction(); 
    ft.replace(R.id.fragment_content, new YourFragment()); 
    ft.commit(); 
} 

更改R.id.fragment_contentForm Transaction Fragment的占位符和YourFragment到新创建的Fragment

相关问题