Saturday, 14 February 2015

How to dismiss the DialogFragment in Android ?

* There are two ways you can dismiss a dialog fragment.

* The first is to explicitly call the dismiss() method on the dialog fragment in response to a button or some action on the dialog view.

1- Calling dismiss() :

if ( someview.getId() ==
    //use some callbacks to advise clients
    //of this dialog that it is being dismissed
    //and call dismiss

* The other way to dismiss a dismiss a dialog fragment is to present another dialog fragment.
The way you dismiss the current dialog and present the new one is slightly different than just dismissing the current dialog.

2- Setting up a dialog for a back stack

 if ( someview.getId() == )
   Activity act = getActivity();
   FragmentManager fm = act.getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();

   //null represents no name for the back stack transaction

   HelpDialogFragment hdf = HelpDialogFragment.newInstance(R.string.helptext) ; ft, "HELP");

No comments:

Post a Comment