I am trying to execute a callback from DialogFragment . There is a good example, but they do not open this DialogFragment from Fragment . http://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents
So here is my code:
public class EditDateDialogFragment extends DialogFragment {
In RecordDetailFragment.java, I implement the interface and create a new instance of EditDateDialogFragment this way (only the important parts):
public class RecordDetailFragment extends SherlockFragment implements EditDateDialogFragment.EditDateDialogListener { ... DialogFragment editDateFragment = EditDateDialogFragment.newInstance( recordId ); editDateFragment.show(getActivity().getSupportFragmentManager(), "EditDateDialogFrame"); @Override public void onDialogPositiveClick(DialogFragment dialog) { LOGD(TAG, "Overriden Dialog confirmed");
Now public void onAttach(SherlockActivity activity) in EditDateDialogFragment never called because I create a DialogFragment from Fragment instead of Activity ? How to fix it?
UPDATE: In RecordDetailFragment, I insert this in onCreate ()
if (savedInstanceState != null) { EditDateDialogFragment dpf = (EditDateDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag("EditDateDialogFragment"); if (dpf != null) { dpf.setListener((EditDateDialogListener) this); } }
I changed the DialogFragment dialog instance to
EditDateDialogFragment editDateFragment = EditDateDialogFragment.newInstance( recordId ); editDateFragment.setListener((EditDateDialogListener) this); editDateFragment.show(getActivity().getSupportFragmentManager(), "EditDateDialogFragment");
Pay attention to EditDateDialogFragment instead of DialogFragment. I am not sure how to update the link in the dialog.
source share