Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh fragment when dialogfragment is dismissed

Tags:

Is there any way I can detect when a DialogFragment is dismissed, so that i can update its parent fragment?

like image 374
tyb Avatar asked Mar 24 '12 16:03

tyb


People also ask

How do you finish DialogFragment?

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.

Is DialogFragment deprecated?

This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.

What is the difference between dialog & DialogFragment?

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.

How do you pass arguments to DialogFragment?

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.


2 Answers

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"); 
like image 185
Ricardo Markiewicz Avatar answered Sep 29 '22 03:09

Ricardo Markiewicz


Override onDismiss() of DialogFragment, or when building the underlying dialog, set a listener with setOnDimissListener().

like image 42
cottonBallPaws Avatar answered Sep 29 '22 02:09

cottonBallPaws