Getting reference to nested fragment from FragmentTabHost

后端 未结 4 517
走了就别回头了
走了就别回头了 2021-02-07 05:11

In my application, I use an Activity which holds one Fragment with FragmentTabHost and hence all its tabs are nested Fragments

4条回答
  •  爱一瞬间的悲伤
    2021-02-07 05:45

    I was trying this for a while, but I was getting null returned from the FragmentManager because I was trying to access the manager in onCreateView() immediately after adding.

    Here is a good explanation on what happened

    It's also important to note that Fragment tabs that have not yet been selected don't exist yet in the FragmentManager, and so will return null as well. I got around this by calling mTabHost.setCurrentTab(index) before trying get to the Fragment with the FragmentManager. It's not very clean, but it works.

提交回复
热议问题