Tuesday 10 February 2015

What is DialogFragment in Android ?

* Dialog-related functionality uses a class called DialogFragment.

* A DialogFragment is derived from the class Fragment and behaves much like a fragment.

* You will then use the DialogFragment as the base class for your dialogs.

* Once you have a derived dialog from this class such as

public class MyDialogFragment extends DialogFragment { ..... }

you can then show this dialog fragment MyDialogFragment as a dialog using a fragment transaction.

Showing a Dialog Fragment :

SomeActivity
{
   //......other activity functions

         public void showDialog()
         {
             //construct MyDialogFragment
             MyDialogFragment mdf = MyDialogFragment.newInstance( arg1, arg2 );
             FragmentManager fm = getFragmentManager();
             FragmentTransaction ft = fm.beginTransaction();
             mdf.show( ft, "my-dialog-tag");
         }
         //.....other activity functions
}

Steps to show a dialog fragment are as follows :
  1.   Create a dialog fragment.
  2. Get a fragment transaction.
  3. Show the dialog using the fragment transaction from step 2.


No comments:

Post a Comment