片段管理 android

Fragment managment android

我想从导航抽屉菜单的片段传递到菜单外的片段。我设法显示新的片段,但被覆盖到以前的片段。你能给我推荐一些 link 吗?

    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction t1 = manager.beginTransaction();
    DetailFragment instance = new DetailFragment();
    Bundle b2 = new Bundle();
    b2.putString("Title", Title);
    b2.putString("author", author);
    instance.setArguments(b2);
    t1.replace(R.id.nav_host_fragment, instance);
    t1.commit();

问题是R.id.nav_host_fragment

public void routine(String Title, String author,Fragment fragment,FragmentManager f1) {

    FragmentTransaction t1 = f1.beginTransaction();
    DetailFragment instance = new DetailFragment();
    Bundle b2 = new Bundle();
    b2.putString("Title", Title);
    b2.putString("author", author);
    instance.setArguments(b2);
    t1.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    t1.replace(fragment.getId(), instance,"Change layout");
    t1.commit();
}

上面的函数被我在下面代码中的第一个片段调用并传递给下一个片段,其中第一个片段来自导航栏片段,下一个片段是一个空片段

                    androidx.fragment.app.Fragment fragment =getParentFragment();
                    instance.routine(Title[position],Author[position],fragment,
                            instance.getSupportFragmentManager());