Activity And Fragment Interaction

前端 未结 7 1248
南旧
南旧 2020-12-10 12:54

I have an Activity with multiple Fragments. I want to show a DialogFragment or open another Fragment from one of the

7条回答
  •  时光说笑
    2020-12-10 13:30

    Have you tried something like this (from the Fragment):

    FragmentTransaction ft = 
        getActivity().getSupportFragmentManager().beginTransaction();
    Fragment prev = 
        getActivity().getSupportFragmentManager().findFragmentByTag("some_name");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    
    DialogFragment dialogFragment = DialogFragmentClass.newInstance();
    dialogFragment.show(ft, "some_name");
    

    Let me know, cheers.

提交回复
热议问题