RXAndroidNo Comments

444 views.

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

Working with Dialog Boxes

The Android Dialog class (android.app.Dialog) is the base class for all types of dialog controls that we can use within our Activity classes. Dialogs exists within the lifecycle of our Activity (android.app.Activity). They pop up in the foreground, blocking of our Activity screen, to catch the user’s attention for a variety of reasons.

The Purpose of Dialogs :

  • Inform the user of some event or progress (e.g. “You have mail!” Or “Downloading Message 1 of 200,000”)
  • Force the user to confirm an action (e.g. “Are you sure you want to delete all your contacts? Really sure?”)
  • Prompt the user for further information and collect it (e.g. “Please enter your username and password.”)

A Note on Toast Messages: Some developers also use Toast messages (android.widget.Toast) for sending simple notifications or messages to the user. A Toast message displays over our Activity screen for a few seconds and then disappears automatically.

Toast over a Dialog is as follows: if the user is being informed of non-essential information, use a Toast, but if information is essential, use a Dialog. We use Toasts as very lightweight, informational notifications.

Displaying Custom Toast :

Structure of Dialogs :
Dialogs have a number of different components, most of which are optional. A basic Dialog has:
 A title
 A message
 Buttons to collect user responses (e.g. Yes, No, Cancel, etc.)
A common Dialog configuration is shown below:

We can also create custom Dialog controls,
Types of Dialogs :
Dialog: Base class for all dialogs. It is usually used to inform user and is the simplest form of a dialog.
AlertDialog: This dialog contains a number of buttons as shown in figure. It is used to get user confirmation on some specific operations like delete a file.
CharacterPickerDialog: It is used to pick an accented character that is associated with base character.
DatePickerDialog: It contains DatePicker control. It is used to collect data from user.
ProgressDialog: It contains a ProgressBar control. It is used to update the status of an operation. For example, file transfer is in progress.
TimePickerDialog: It contains a TimePicker.

m1 m2 m3

m4 m5 m6
Example : Develop Android app to display all dialogs

main.xml

AllDialogActivity.java

 

Be the first to post a comment.

Add a comment