Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 ANDROID DIALOGS

2 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 http://developer.android.com/guide/topics/ui/dialogs.html

3 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

4 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

5 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

6 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

7 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

8 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

9 Slide 9 Creating the AlertDialog (Step 3-1) Create the positive button Note that the type of the listener is DialogInterface

10 Slide 10 Creating the AlertDialog (Step 3-2) Create the Positive button and the response to the button’s click event.

11 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

12 Slide 12 The Date Constructor

13 Slide 13 Date Operations (Methods) See http://developer.android.com/reference/java/ util/Date.html http://developer.android.com/reference/java/ util/Date.html

14 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”

15 Slide 15 DatePickerDialog (Introduction) The constructor creates the dialog box The show method displays it We typically handle the DatePickerDialog.OnDateSetListener event

16 Slide 16 DatePickerDialog (Constructor) The constructor accepts the following arguments: Example

17 Slide 17 DatePickerDialog (Creating the Listener) PickDate implements the onDateSet listener, which fires when the user selects a date

18 Slide 18 TimePickerDialog (Introduction) It operates similar to the DatePickerDialog The constructorHandler the OnTimeChangedListener http://developer.android.com/reference/android /app/TimePickerDialog.html http://developer.android.com/reference/android /app/TimePickerDialog.html


Download ppt "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."

Similar presentations


Ads by Google