获取引用来自FragmentTabHost嵌套的片段 [英] Getting reference to nested fragment from FragmentTabHost

查看:147
本文介绍了获取引用来自FragmentTabHost嵌套的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用活动持有一个片段 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)

这篇关于获取引用来自FragmentTabHost嵌套的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆