2016-11-14 84 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

相關問題