访问片段外的片段变量

时间:2013-11-21 22:44:51

标签: android android-fragments

我有一个活动,多个片段和多个子视图。在某些情况下,我必须访问附加了子视图(扩展RelativeLayout)的片段变量。我怎么能这样做?

我可以通过

访问视图
getActivity().getFragmentManager.getFragmentByTag("TAG").getView().findViewById()

但无法访问该片段中的变量。

1 个答案:

答案 0 :(得分:0)

getFragmentByTag返回Fragment,尝试将您返回到实现类的片段转换为然后访问它们:

((MyCustomFragment)getActivity().getFragmentManager.getFragmentByTag("TAG"))
    .getMySuperSecretField();

如果您发布更多详细信息/代码,我可能能够诊断您更好的问题

相关问题