I am converting my app to use the v4 compatibility package and fragments. I have done well so far, but I need to launch a DialogFragment from a preference click in a PreferenceActivity
. Since there isn't a PreferenceFragment in the compatibility library, I'm stuck with using PreferenceActivity
. Is it possible to get a reference to the fragment manager and call the DialogFragment
or do I just have to continue using the old dialog if I need a dialog from a preference?
To create a DialogFragment , first create a class that extends DialogFragment , and override onCreateDialog() , as shown in the following example. Similar to how onCreateView() should create a root View in an ordinary fragment, onCreateDialog() should create a Dialog to display as part of the DialogFragment .
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.
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.
tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment.
Not without jumping through hoops.
You could make a very simple activity with the sole purpose of launching the DialogFragment. If you do this you will need to finish() that activity when the DialogFragment dialog has been dismissed.
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