Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to launch a DialogFragment from a Preference in a PreferenceActivity?

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?

like image 396
ssuperz28 Avatar asked Oct 27 '11 21:10

ssuperz28


People also ask

How do I start a DialogFragment?

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 .

What is the difference between dialog & 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.

What is DialogFragment explain its uses?

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.

How to close Dialog Fragment?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment.


1 Answers

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.

like image 161
roflharrison Avatar answered Sep 24 '22 05:09

roflharrison