简体   繁体   中英

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'.

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.

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 ).

So when the data is input, it will be passed to 'H'.

Then when the button is pressed in fragment C, it can just pull that data from the host activity.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM