Android Programming: The Big Nerd Ranch Guide, 2nd Edition
by Bill Phillips, Chris Stewart, Brian Hardy, Kristin Marsicano
Creating a DialogFragment
When using an AlertDialog, it is a good idea to wrap it in an instance of DialogFragment, a subclass of Fragment. It is possible to display an AlertDialog without a DialogFragment, but it is not recommended. Having the dialog managed by the FragmentManager gives you more options for presenting the dialog.
In addition, a bare AlertDialog will vanish if the device is rotated. On the other hand, if the AlertDialog is wrapped in a fragment, then the dialog will be re-created and put on screen after rotation.
For CriminalIntent, you are going to create a DialogFragment subclass named DatePickerFragment. Within DatePickerFragment, you will create and configure an instance of AlertDialog that displays a DatePicker ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access