Consider an activity we can call as a base activity. Two fragments are added to this base activity , call as fragmentOne and fragentTwo.How can fragmentOne can communicate with fragentTwo and vice versa .
-
1Can you please post your code which you tried so far.. ? – user1140237 Jan 16 '16 at 08:04
-
1please always post whatever you tried so far. – NarenderNishad Jan 16 '16 at 08:12
-
any changes in fragmenttwo get notify in fragmentone and vice versa like interface.How we can simply implement this. – jobi mg Jan 16 '16 at 08:28
-
check this answer http://stackoverflow.com/a/37701651/1153703 – Bikesh M Jun 08 '16 at 11:58
3 Answers
You can define interface
to communicate between fragments.
go through this link
http://developer.android.com/training/basics/fragments/communicating.html
hope it helps.

- 684
- 5
- 13
refer Communicating with Other Fragments,the communication among fragments should by activity,we'd better don't use directly communicate.We must know fragment lifecycle must depend on activity,and considering coupling of classes,we should let fragment do own task and other tasks need to communicate with other class should by its holder activity.

- 8,228
- 6
- 41
- 52
All communication between fragments should be implemented through the activity. For example, if you want to call method foo() inside Fragment1 from Fragment2, add intermediary method to activity, which contain both fragments (for example MainActivity):
public void foo(){
Fragment f = getFragmentManager().findFragmentById(R.id.fragment1);
if (f != null) {
((Fragment1) f).foo();
}
}
Now you can call it from Fragment2: ((MainActivity)getActivity()).foo()
But don't forget, that all fragments have own lifecycles.

- 2,135
- 18
- 20