Reputation: 1746
There appears to be some points of contention regarding how to send information between fragments. For example, say I have two SherlockFragments, one that holds a textfield and a button, which lets me add items to a list, and then a second fragment which prints out that list. One post recommends sending the data directly from one tab to the other: How to transfer some data to another Fragment?. Another recommends using Otto or Roboguice: How to pass data between fragments.
Because I am new to this and some of what I found might be outdated, I would very much appreciate any suggestions for how to accomplish this simple feat (if it is!).
Thank you so much for your help.
Upvotes: 1
Views: 1607
Reputation: 4522
All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.
To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity. The Fragment captures the interface implementation during its onAttach() lifecycle method and can then call the Interface methods in order to communicate with the Activity.
For more details and example you can read this official documentation.
Upvotes: 6