Try this approach: Add the following to your module
level build.gradle
file
compile 'org.greenrobot:eventbus:3.0.0'
Then, create a regular java class that represents your Event.
public class UpdateFragmentsUIEvent{
//add your values you want to pass to your other fragments
private String valueA;
private String valueB;
private String valueC;
//.....others?
public UpdateFragmentsUIEvent(){
}
//add getters and setters here
}
Now that you have created your event class, in the fragment that you want to update (not the first one, but the ones you want to pass the data to), do the following:
public class FragmentB extends Fragment{
@Override
public void onAttach(Context context){
super.onAttach(context);
//important here - could be done inside onCreate()
EventBus.getDefault().register(this);
}
//very important here as well
public void onEvent(UpdateFragmentsUIEvent event){
/* this event instance has all your values here now */
String valueA = event.getValueA();
String valueB = event.getValueB();
/* Now you can update your views accordingly */
}
/* don't forget to unregister inside onDestroy */
@Override
public void onDestroy(){
super.onDestroy();
EventBus.getDefault().unregister(this);
}
}
Finally, to actually notify your fragments, you have to post your newly minted event like this inside the first fragment I suppose is where you enter values :
//somewhere when a button is clicked after entering data
EventBus.getDefault().post(new UpdateFragmentsUIEvent(valueA, valueB, valueC));
And just like that, you are done! Forget about the interfaces and stick to recommended design patterns that follows loose coupling of code like the publisher/subscriber pattern used in this example.
I hope this helps and please let me know if you need more help!