Show Alert Dialog Android SampleAndroid Code Samples [April 05, 2013 at 2:24 AM] 3,385 views
1. Introducing Android Alert Dialog
Dialog boxes are a common UI metaphor in desktop and web applications. They ’re used to help users answer questions, make selections, confirm actions, and read warning or error messages. An Android Dialog is a floating window that partially obscures the Activity that launched it.
Creating alert dialog is very easy. In this tutorial i will be discussing about creating different alert dialogues with one button(ok button), two buttons(yes or no buttons) and three buttons(yes, no and cancel buttons).
2. Showing Alert Dialog
2.1. Android alert dialog with One Button
The following code will create a simple alert dialog with one button. In the following code setTitle() method is used for set Title to alert dialog. setMessage() is used for setting message to alert dialog. setIcon() is to set icon to alert dialog.
2.2. Android alert dialog with Two Button
The following code will create alert dialog with two button. setPositiveButton() is used to create a positive button in alert dialog and setNegativeButton() is used to invoke negative button to alert dialog.
2.3. Android alert dialog with Three Button
Here setNeutralButton() is used to create a neutral cancel button
2.4. Android alert dialog with Custom Layout
Now, we will create a alert dialog with custom layout.
3. Sample Code
Create XML layout: main.xml
Tags: Alert Dialog, Android Samples