I have an activity
public class ShowFileActivity extends FragmentActivity
and when occours some event, this class call a DialogFragment
public class ConfirmDialog extends DialogFragment
that is a simple confirm dialog (with "dismiss" and "ok" button). If user press dismiss button, i call
dismiss()
and come back to ShowFileActivity. Else, if user press ok, after made some operations, after call dismiss on dialog, i would go back to parent activity of ShowFileActivity. There's a way to do it? Does DialogFragment launch any event to his parent view?
tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
Showing the DialogFragment Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.
Android DialogFragments. DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.
What you can do is to call a method of the containing activity from inside the fragment. As per any other fragment, you can call getActivity() which returns the containing activity.
@Override
public void onDismiss(DialogInterface dialog) {
ShowFileActivity parent = (ShowFileActivity) getActivity();
parent.doWhateverYouWantWhenDialogDismissed();
}
Another (more fancy) approach would be to use an event bus such as otto or greenrobot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With