简体   繁体   English

在片段的viewpager中,如何请求将数据从一个片段拉到另一个片段

[英]In a viewpager of fragments, how to request to pull data from one fragment to another

I have fragments 'A,B,C' inside host Activity 'H'. 我在宿主活动'H'中有片段'A,B,C'。

I want to click a button in C, which will pull user inputted data from textviews or something in A and B. So that when it is done, I have collected all the data placed in fragments A,B and C. 我想点击C中的一个按钮,它将从文本视图或A和B中的内容中提取用户输入的数据。这样,当它完成时,我已经收集了放在片段A,B和C中的所有数据。

I imagine this requires some sort of interface but I'm a little confused as to how this might be done. 我想这需要某种界面,但我对如何做到这一点感到困惑。

I see this example shows how to pass data From a fragment to the host, and from the host to a fragment, but I'm not sure how to request info from one fragment to another. 我看到这个例子展示了如何将数据从片段传递到主机,从主机传递到片段,但我不知道如何从一个片段向另一个片段请求信息。

Create callbacks to the host activity in A and B (see http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity ). 在A和B中创建对主机活动的回调(请参阅http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity )。

So when the data is input, it will be passed to 'H'. 因此,当输入数据时,它将被传递给'H'。

Then when the button is pressed in fragment C, it can just pull that data from the host activity. 然后,当在片段C中按下按钮时,它只能从主机活动中提取该数据。

So basically, don't communicate directly between fragments, but rather push and pull your variables from the host activity. 所以基本上,不要在片段之间直接通信,而是从宿主活动中推送和提取变量。 (Use the callbacks for 'pushing'). (使用'推送'的回调)。

Also, see this link: http://developer.android.com/training/basics/fragments/communicating.html 另请参阅此链接: http//developer.android.com/training/basics/fragments/communicating.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将数据从对话片段发送到Viewpager中的所有片段? - How to send data from a dialogue fragment to all fragments within a Viewpager? 如何在ViewPager中将一个片段的值传递给另一个片段? - How to pass values from one Fragment to another in a ViewPager? 从第二个Fragment的recyclerView中选择项目时如何切换到第一个Fragment? 两个片段都在带有 viewPager2 的 tablayout 中 - How to switch to the first fragment when selecting an item from the recyclerView of second Fragment? Both fragments are in tablayout with viewPager2 如何将捆绑数据从一个片段获取到另一个片段? - How to get bundle data from one fragment to another fragment? Android:通过ViewPager从一个片段滚动到另一个片段 - Android: Scrolling from one Fragment to another through a ViewPager 从另一个Fragment Android调用的Fragment中的ViewPager - ViewPager in Fragment called from another Fragment Android 如何从一个片段中删除数据,这些片段应该反映在google firebase中的其他片段中 - how to delete data from one fragment that should be reflected in other fragments in google firebase Android-如何从ViewPager中的另一个片段更新我的Recyclerview? - Android - How to update my recyclerview from another fragment in a viewpager? 如何从一个片段移动到另一个片段? - How to move from one fragment to another fragment? 如何将数据从列表视图从一个片段发送到另一个 - How to send data from listview from one fragment to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM