findFragmentById always returns null

前端 未结 9 597
时光说笑
时光说笑 2020-12-01 17:31

I\'m defining an ID for my fragment in the xml layout:




        
9条回答
  •  [愿得一人]
    2020-12-01 18:05

    The reasons mentioned above are valid but another possible reason is that you are trying to search for the fragment while being in a fragment this also results in fragmentManager.findFragmentById to return null. We should use childFragmentManager.findFragmentById to find the fragment inside a fragment. According to the official documentation.

    public final androidx.fragment.app.FragmentManager getChildFragmentManager()

    Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

提交回复
热议问题