Code the DatePicker Dialog

The DatePicker dialog is a window that opens when the user presses the Change button. A custom dialog requires both a layout, which you have already created, and a class that contains the code that gives the dialog its behavior. Using a custom dialog in an activity also requires changes to the activity code. The following describes how to code the DatePickerDialog class and make changes to the ContactActivity to display and use the dialog.

The first task is to create a new class to hold the custom dialog code. Right-click com.example.mycontactlist in the src folder and select New > Class from the pop-up menu. Enter DatePickerDialog for the Name and click Finish. The new class opens with a limited amount of code. Replace ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android 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.