获取引用来自FragmentTabHost嵌套的片段嵌套、片段、FragmentTabHost

2023-09-05 23:38:08 作者:挖坟盗墓接单ゝ

在我的应用程序,我使用活动持有一个片段 FragmentTabHost ,因此所有的标签是嵌套的片段

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

里面的活动其持有片段及其嵌套的片段,我们可以得到一个参考连接有一个使用 onAttachedFragment()

Inside an Activity which holds a Fragment with its nested Fragment, we may get a reference to attached one using onAttachedFragment().

可是如何才能让一个引用嵌套的片段 FragmentTabHost

But how to get a reference to nested Fragment from FragmentTabHost?

推荐答案

嗯,探索 FragmentTabHost 来源$ C ​​$ C,我发现,当它增加了一个片段选项卡,它assignes 则tabspec 的嵌套标记片段

Well, exploring the source code of FragmentTabHost I've found that when it adds a fragment tab, it assignes a tag of TabSpec to nested Fragment.

所以拿到参照本片段我们应该叫

So to get the reference to this Fragment we should call

getChildFragmentManager()。findFragmentByTag(tabSpecTag)