0

I have a fragment and a dialogfragment, I want to communicate between them: send data from fragment to dialogfragment and send data from dialogfragment to fragment

I read about setTargetFragment and getTargetFragment but I couldnot understand how to use them correctly to send/receive data to/from dialogfragment.

any help?

Atef Hares
  • 4,715
  • 3
  • 29
  • 61
  • You should have an activity, right? You know how to communicate between activity and fragment, and activity between dialog? then you can communicate between dialog and fragment over activity. – Devrim May 01 '16 at 15:30
  • It would be better understanding if you post your code – Masum May 01 '16 at 15:31
  • @DevrimTuncer, but I want to learn how to communicate between fragments directly for in case if fragments aren't in the same Activity – Atef Hares May 01 '16 at 15:34
  • @Masum, I am talking about very simple fragments – Atef Hares May 01 '16 at 15:34

2 Answers2

1

There's answer for this already. Look at this for Communication between Fragment and DialogFragment - if this helps you, you can accept the answer, otherwise you should motivate why your specific problem is different from the one presented in here.

To see how to use the setTargetFragment and getTargetFragment, you can look at the [selected answer here] (How to get data from DialogFragment to a Fragment?) - specifically, you might find the code helpful for what you want to do.

Community
  • 1
  • 1
ishmaelMakitla
  • 3,784
  • 3
  • 26
  • 32
  • I have read that question, But the answers did not explain how to use `setTargetFragment` and `getTargetFragment` methods – Atef Hares May 01 '16 at 15:45
  • Noted. I have added a reference to an example of how to use these. Please check it out. – ishmaelMakitla May 01 '16 at 16:03
  • Thanks, This [answer](http://stackoverflow.com/a/18025715/5993410) helped me to communicate from `dialogFragment` to `fragment` – Atef Hares May 01 '16 at 16:23
  • This answer ended up in the review queue; it would be better suited as a comment. An answer is ideally more than references to other answers on StackOverflow. – Zong May 01 '16 at 21:49
0

So, I have Communicated from DialogFragment to Fragment using this way

and Communicated from Fragment to dialogFragment using setArguments() and Bundel

Community
  • 1
  • 1
Atef Hares
  • 4,715
  • 3
  • 29
  • 61