[英]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.