ANDROID DIALOGS
Slide 2 Dialogs (Introduction) The Dialog class is the base class for all dialogs A dialog is a small window that prompts the user to make a decision or enter additional information Avoid instantiating the Dialog class directly. Instead uses one of the subclasses Note that dialogs were added with API level 11
Slide 3 Dialogs (Types) Use the AlertDialog to display a dialog with up to 3 buttons, selectable items, or custom layout Use the DatePickerDialog or TimePickerDialog to select a date or time Use the DialogFragment as a container for the dialog You can create custom dialogs too
Slide 4 AlertDialog (Introduction) It can display one, two, or three buttons It can display a title And we can get data from the alert
Slide 5 A First AlertDialog (Example) The following steps are involved in building the dialog Create the AlertDialog Set the Title and Message Create the buttons Show the AlertDialog Optionally get data back from the dialog
Slide 6 Creating the AlertDialog (Step 1) The AlertDialog has a static inner class that creates the dialog box The constructor for this inner class accepts one argument The name of the parent activity
Slide 7 Creating the AlertDialog (Step 2) Call setTitle to give the dialog a title Call setMessage to the descriptive prompt Call setCancelable to indicate whether the dialog can be cancelled by pressing the BACK key
Slide 8 Creating the AlertDialog (Step 3) There are a few ways to create the buttons To create Yes / No buttons, call setPositiveButton and setNegative button. setNeutalButton is the center button The first argument contains the button text The second contains the event listener
Slide 9 Creating the AlertDialog (Step 3-1) Create the positive button Note that the type of the listener is DialogInterface
Slide 10 Creating the AlertDialog (Step 3-2) Create the Positive button and the response to the button’s click event.
Slide 11 A Few Words about Dates The Android Date class represents a moment in time with millisecond precision Measured in UTC Constructors create dates using a current date or time Methods manipulate those dates
Slide 12 The Date Constructor
Slide 13 Date Operations (Methods) See util/Date.html util/Date.html
Slide 14 Selecting Dates (Introduction) Date pickers can be implemented in one of two ways Use the DatePicker to render the widget Use the DatePickerDialog which encapsulates the widget This is another of those “helper classes”
Slide 15 DatePickerDialog (Introduction) The constructor creates the dialog box The show method displays it We typically handle the DatePickerDialog.OnDateSetListener event
Slide 16 DatePickerDialog (Constructor) The constructor accepts the following arguments: Example
Slide 17 DatePickerDialog (Creating the Listener) PickDate implements the onDateSet listener, which fires when the user selects a date
Slide 18 TimePickerDialog (Introduction) It operates similar to the DatePickerDialog The constructorHandler the OnTimeChangedListener /app/TimePickerDialog.html /app/TimePickerDialog.html