An android alertdialog/ alert-box is used to show a alert message to user and getting conformation regarding the message as in previous tutorial on toast we can see a message is just displayed to user irrespective of confirmation but now user needs to confirm which in turn called to be a alert-box.

http://www.androidcoding.in/2016/01/26/android-tutorial-on-toast/

 

In alert boxes we can set three types of buttons like

1. Positive button

2. Neutral button

3. Negative button

 

Beside these buttons you can also set a Title for your alert-box, and a message which is to be displayed.

Generally we can see only two buttons and even a single positive button can be used in android alertdialog.

If there is a requirement for any additional buttons or an other fields like android edittext , textviewwe can make a android custom alertdialog for reference visit this link.

android dialog with custom layout 

http://www.androidcoding.in/2016/02/11/android-tutorial-on-dialog-box/

 

Setting title for alertbox

Setting message

 

asas

MainActivity.java

You can add a piece of code to dismiss the dialog box in negative button click i.e., “cancel” button here 

   

Add textview and button to xml screen by which we can display a alert-box.

 

activity_main.xml

AndroidManifest.xml

Output :

alert-box1

Show Buttons
Hide Buttons
Read previous post:
Android Tutorial on Toast

Close