Creating Your First Alert Dialog Box
Have you ever worked with an application that did not inform you of a warning or did not alert you of something? If not, take the following example into consideration. Imagine an e-mail client that does not inform you that you have new e-mail. How annoying would that be? Alerting users of important issues or choices that need to be made is an integral part of any user experience. A few examples of where you might want to use a dialog box to inform the user of a message and/or to have the user perform an action are as follows:
- Something is happening in the background (this is what a ProgressDialog does).
- The values in an EditText view are invalid.
- The network has become unavailable.
- The user needs to select a date or time (as I just demonstrated).
- The state of the phone is not compatible with the application. Maybe the app needs to be GPS enabled or needs an SD Card, and you've detected these issues upon the application starting.
- The user needs to choose from a list of items.
Although this is not a comprehensive list, it does give you an inkling of what is possible with dialog boxes.
The Android system has a framework built around dialog boxes that enables you to provide any implementation that you may need.
Various types of dialog boxes are available, including these, the most common:
- Alert: Alerts the user of something important. Also allows the user to set the text value of the buttons, as well as the actions performed, when they are clicked. ...
Get Android™ Tablet Application Development For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.