Skip to content Skip to sidebar Skip to footer

Sending Data From Fragment To Fragment

I am beginner at Android programming currently practicing Fragments. I have 3 Fragments and I would like to send some data from one to another. In ArtistFragment I have a list of a

Solution 1:

Fragment can't communicate directly. This happens throught the Activity. Two Fragments should never communicate directly. Take a look at this: http://developer.android.com/training/basics/fragments/communicating.html

There is another way that I prefer, which is using Event Bus like otto: http://square.github.io/otto/

Using otto you can publish events from one Fragment and subscribe to that event from the other Fragment.

Solution 2:

It is not a good idea to try to communicate directly from one fragment to another one.

The best way is to provide a Callback interface in the activity that to be implemented in the activity or in your case this could be in FragmentPagerAdapter Take a look at [http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity][1]

In the callback method you could pass whatever parameters you want and then to start for example the other fragment.

Post a Comment for "Sending Data From Fragment To Fragment"