Creating a DialogFragment

When displaying a DatePickerDialog, it is a good idea to wrap it in an instance of DialogFragment, a subclass of Fragment. It is possible to display a DatePickerDialog without a DialogFragment, but it is not recommended. Having the DatePickerDialog managed by the FragmentManager gives you more options for presenting the dialog.

In addition, a bare DatePickerDialog will vanish if the device is rotated. If the DatePickerDialog is wrapped in a fragment, then the dialog will be re-created and put back onscreen after rotation.

For CriminalIntent, you are going to create a DialogFragment subclass named DatePickerFragment. Within DatePickerFragment, you will create and configure an instance of DatePickerDialog ...

Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.