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, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.