How to Show Alert Dialog in Android


Android Layout Files

We use the Alert Dialog to display alert messages.The AlertDialog is a small window that opens and warns us about objects and makes selections based on our selection.

  • File : res/layout/activity_main.xml

  • The screen image looks like the following

MainActivity

  • Alert dialog code to be displayed when the user presses this button

File : MainActivity.java

  • The alert dialog will be displayed when the show button is pressed

  • As you can see from the code, the dialog will close after you hit the arrow button(dialog.dismiss())

 

You may also like...

Leave a Reply

Your email address will not be published.