调用从父活动一个片段方法 [英] Calling a Fragment method from a parent Activity
问题描述
我在href="http://developer.android.com/guide/topics/fundamentals/fragments.html"> Android的碎片开发指南这是一个活动可以调用一个方法 findFragmentById()或 findFragmentByTag()
。
I see in the Android Fragments Dev Guide that an "activity can call methods in a fragment by acquiring a reference to the Fragment from FragmentManager, using findFragmentById()
or findFragmentByTag()
."
下面展示了如何获得一个片段的参考,而不是如何调用特定的方法在片段的例子
The example that follows shows how to get a fragment reference, but not how to call specific methods in the fragment.
谁能给一个如何做到这一点的例子吗?我想从父活性片段调用特定的方法。谢谢你。
Can anyone give an example of how to do this? I would like to call a specific method in a Fragment from the parent Activity. Thanks.
推荐答案
得不到的问题,正是因为它太简单了:
not get the question exactly as it is too simple :
ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment);
fragment.<specific_function_name>();
这篇关于调用从父活动一个片段方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!