1. Android Dialogs

1.1. Overview

You can open dialogs from your Activity via the showDialog(int) method. Dialogs are always created and are part of an Activity. A dialog gets the focus until the user closes it.
Dialog is the base class for dialogs, typically you use on of its subclasseds, e.g. AlertDialog,ProgressDialog,DatePickerDialog or TimePickerDialog.

If the dialog is displayed the first time Android calls the onCreateDialog(int) method. In this method you instantiate the correct dialog based on the input parameter. You should always create a dialog from the onCreateDialog(int) method as the Android system manages in this case the dialog for you.

onCreateDialog(int)is only called the first time, if you want to later influence the dialog use the optional onPrepareDialog(int, Dialog) method.

1.2. ProgressDialog

Android provides also a ProgressDialog, which can be opened via a ProgressDialog.open()method call.

1.3. Own Dialogs

If you want to create your own dialogs, you create a layout file for the dialog. This layout file is assigned to the dialog via the setContentView() method.
You would then use the dialog.findViewById() to find the elements in your layout and assign values to it.
The title of the dialog can be set via the setTitle() method.

2. Tutorial: Alert Dialog

The following will give an example of using the AlertDialog dialog An instance of this class can be created by the builder pattern, e.g. you can chain your method calls.
Create a new Android project named "de.vogella.android.dialog.alert" with the Activity calledAlertExampleActivity. Maintain the following layout for main.xml.