片段及其容器活动之间传递数据 [英] Passing data between a fragment and its container activity
问题描述
我怎样才能片段及其容器活动之间传递数据?有没有通过类似的意图传递活动之间数据的东西吗?
How can i pass data between a fragment and its container activity? Is there something similar to passing data between activities through intents?
我读到这样的:<一href="http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity">http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity
但它并没有多大帮助。 任何帮助AP preciated
But it didn't help much. Any help is appreciated
推荐答案
在你的片段,你可以调用getActivity()。这会给你访问创建该片段的活性。从这里可以很明显的调用都在活动的任何形式的访问方法。
In your fragment you can call getActivity(). This will give you access to the activity that created the fragment. From there you can obviously call any sort of accessor methods that are in the activity.
这篇关于片段及其容器活动之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!