<font class="popmake-631">Subscribe</font>Subscribe with Androidlift to get new post on mail.

how to create AlertDialog

Android create alert dialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue.

  • Android alert dialog that can show
  1. Title
  2. Up to three buttons (positive, negative and neutral)
  3. List of electable items
    1. A traditional single-choice list
    2. A persistent single-choice list (radio buttons)
    3. A persistent multiple-choice list (check-boxes)
  4. custom layout.
  • Android Alert Dialog is composed of three regions: title, content area and action buttons.
  • Android Alert Dialog is the subclass of Dialog class.

But in this article we are going to implement the second one that is two buttons dialog(positive and negative) respectively.

Android create alert dialog

Let’s see a simple example of android alert dialog.

android create alert dialog Output :

android create alert dialog
android alert dialog


Create activity_main.xml file and add the following code in it.

res -> values -> strings.xml

Create strings.xml file and add the following code in it.



Create MainActivity.javeĀ file and add the following code in it.

Best luck !

Please subscribe with us to get latest updates and like us on social channels if we are doing great job…..!