从父 Activity 调用 Fragment 方法 [英] Calling a Fragment method from a parent Activity

查看:37
本文介绍了从父 Activity 调用 Fragment 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Fragments Dev Guide 中看到一个活动可以通过使用 findFragmentById()findFragmentByTag() 从 FragmentManager 获取对 Fragment 的引用来调用片段中的方法."

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.

谁能举例说明如何做到这一点?我想从父 Activity 调用 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>(); 

这篇关于从父 Activity 调用 Fragment 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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