Is there any way I can detect when a DialogFragment is dismissed, so that i can update its parent fragment?
Show activity on this post. 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.
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs. It allows the FragmentManager to manage the state of the dialog and automatically restore the dialog when a configuration change occurs.
you can set your args. class IntervModifFragment : DialogFragment(), ModContract. View { companion object { fun newInstance( plom:String,type:String,position: Int):IntervModifFragment { val fragment =IntervModifFragment() val args = Bundle() args. putString( "1",plom) args.
You can add a listener and override the onDismiss of your fragment dialog :
public class DismissDialog extends DialogFragment { private DialogInterface.OnDismissListener onDismissListener; public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { this.onDismissListener = onDismissListener; } @Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); if (onDismissListener != null) { onDismissListener.onDismiss(dialog); } } }
Then, on the parent, you set a listener :
DismissDialog d = new DismissDialog(); d.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { } }); d.show(getSupportFragmentManager(), "sometag");
Override onDismiss() of DialogFragment, or when building the underlying dialog, set a listener with setOnDimissListener().
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