I have a main class:
public class MainFragment extends Fragment implements OnClickListener, OnMarkerClickListener {}
I have a dialog class:
public class PedirTaxiDialog extends SimpleDialogFragment implements
OnClickListener{}
For example: I have FragmentA from which I start SimpleDialogFragment (there are EditText in box). How to can I get back the value from the EditText to FragmenaA? I try to make many things ... but I have no sucessy. Help me please !!
In my MainFragment class, I show the dialog class:
FragmentActivity activity;
activity = (FragmentActivity) getActivity().new PedirTaxiDialog().show(activity.getSupportFragmentManager(), "Salvar Favoritos");
I would get the values entered by the user in the dialog class. How can I in my MainFragment get the return of PedirTaxiDialog?
links of classes:
Suppose you have this code where you're creating your dialog
By calling method
setTargetFragment()
you're enabling option to get result from your DialogFragment as you're getting result from activity when you're starting it usingstartActivityForResult()
.So in your DialogFragment when user clicks OK button, in the OnClickListener you have to create intent, put to it as String Extra text user entered, set Result_OK and call
getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, yourIntent)
like this:And then in your MainFragment override
onActivityResult()
method: