Fragment declared target fragment that does not belong to this FragmentManager

前端 未结 3 2114
温柔的废话
温柔的废话 2020-12-29 08:17

I have made an activity A which has a fragment X in it. In fragment X, EditText item has on click event which opens fragment Y. This fragment displays a list of names. I pre

相关标签:
3条回答
  • 2020-12-29 08:19

    To use setTargetFragment(), both the new Fragment and the target Fragment must be hosted within the same FragmentManager. The most common case where this would not happen is if you are using Activity.getSupportFragmentManager() or Fragment.getFragmentManager() alongside Fragment.getChildFragmentManager().

    0 讨论(0)
  • 2020-12-29 08:26

    To new users where the "getFragmentManager" only work for it but don't want use deprecated method, the method "getParentFragmentManager" work too.

    0 讨论(0)
  • 2020-12-29 08:33

    In my solution, replace

    getChildFragmentManager()
    

    with

    Activity.getSupportFragmentManager() or Fragment.getFragmentManager()
    

    that worked for me. Thank Mr.Ben P

    0 讨论(0)
提交回复
热议问题