I'm trying to make a Fragment
to show a Dialog
using DialogFragment
API.
My dialog only has an EditText
view and I want to pass the string wrote on it back to the Fragment
.
I'm able to show the dialog from the Fragment
, but I'm not able to retrieve the string from the input field back to my Fragment
.
I tried both ways to create a dialog: overwriting the DialogFragment.onCreateView
method and writing the entire dialog's view and overwriting the DialogFragment.onCreateDialog
and using the AlertDialog.Builder
to make it easier to write the buttons behavior.
The Android documentation about dialogs passing events back to dialog's host is about host being always an Activity
and never a Fragment
. I tried to generalize the behavior for use it on my case, but I cannot.
I tried using the DialogFragment.onAttach
callback to get the Activity
reference and use an interface between the Fragment
and the DialogFrament
and it works fine, but I cannot retrieve the Fragment
from the Activity
to make it work.
Can anybody help with a brief example?
Thanks in advance