Dialog
To organize information and react to user-driven events.E.g. an activity might display a dialog informing the user of a problem or ask the user to confirm an action such as deleting a data record.
Types of Dialog:
Dialog: The basic class for all Dialog types.AlertDialog: A Dialog with one, two, or three Button controls.
CharacterPickerDialog: A Dialog for choosing an accented character associated with a base character.
DatePickerDialog: A Dialog with a DatePicker control.
ProgressDialog: A Dialog with a determinate or indeterminate ProgressBar control.
TimePickerDialog: A Dialog with a TimePicker control.
Lifecycle of a Dialog:
Must be defined within the Activity.May be launched once, or used repeatedly.
Key methods that activity must use to manage dialog:
showDialog(): Used to display a Dialog.dismissDialog(): used to stop showing a Dialog. The Dialog is kept around in the Activity’s Dialog pool.
If the Dialog is shown again using showDialog(), the cached version is displayed once more.
removeDialog(): used to remove a Dialog from the Activity objects Dialog pool.
The Dialog is no longer kept around for future use. If you call showDialog() again, the Dialog must be re-created.
steps to add dialog to an activity :
Define a unique identifier for the Dialog within the Activity.
Implement the onCreateDialog() method of the Activity to return a Dialog of the appropriate type, when supplied the unique identifier.
Implement the onPrepareDialog() method of the Activity to initialize the Dialog as appropriate.
Launch the Dialog using the showDialog() method with the unique identifier.
Defining a Dialog:
Each Dialog has a special identifier (an integer).Pass this identifier when showDialog() method is called.
At this point, the onCreateDialog() method is called and must return a Dialog of the appropriate type.
onCreateDialog() method may only be called once for initial Dialog creation.
Initializing a Dialog:
Dialog is often kept around by the Activity in its Dialog pool.To re-initialize a Dialog each time it is shown, instead of just when it is created the first time.
Override the onPrepareDialog() method of the Activity.
onPrepareDialog() method is called each time the showDialog() method is called, giving the Activity a chance to modify the Dialog before it is shown to the user.
Launching a Dialog:
Display any Dialog defined within an Activity by calling its showDialog() method and passing it a valid Dialog identifier.Dismissing a Dialog:
Most types of dialogs have automatic dismissal circumstances. To force a Dialog to be dismissed, simply call the dismissDialog() method and pass in the Dialog identifier.
Removing dialog from use:
Dismissing a Dialog does not destroy it.If the Dialog is shown again, its cached contents are redisplayed.
To force an Activity to remove a Dialog from its pool and
not use it again call the removeDialog() method, passing in the valid Dialog identifier.
Custom Dialog:
To create a custom dialog follow the steps:Design a custom layout resource to display in the AlertDialog.
Define the custom Dialog identifier in the Activity.
Update the Activity’s onCreateDialog() method to build and return the appropriate custom AlertDialog.You should use a LayoutInflater to inflate the custom layout resource for the Dialog.
Launch the Dialog using the showDialog() method.




Posted in: 
0 comments:
Post a Comment