0

As my question, my app has only one a Activity and 2 Fragments (A and B). First, Activity contains fragment A provides to input 2 numbers and a Button. When i click button, dialogFragment B will show to choice the calculation and press Ok button. The fragment B will close and the result will display in Fragment A.

I wan't use the communicating between Fragment - Fragment. Thanks

Truong Vu
  • 204
  • 4
  • 14

1 Answers1

0

Use Interface for communication between fragments, or you can also use OttoBus library.

It depends, how big your application is, in your case, you should go with interfaces.

Create an interface for fragment A, have it implemented in Activity, and then from activity, call the fragment B to update data or anything after receiving it form Fragment A.

Read here to know more about basic communication b/w fragments.

http://developer.android.com/training/basics/fragments/communicating.html

Ritt
  • 3,181
  • 3
  • 22
  • 51
  • Thanks, i think it clear and I understand it. But if I want to use setTargetFragment(), it is possible to do in this situation? – Truong Vu Feb 16 '16 at 07:16
  • yes, you can use, but you then you donot require interafces for communication. And also, it should be used only in specific cases. See here for more clarity.. http://stackoverflow.com/questions/18945938/should-we-be-using-settargetfragment-i-thought-fragments-should-not-be-commun – Ritt Feb 16 '16 at 07:21