android confirm dialog

Android confirm dialog box with OK and Cancel button

This will probably be one of the Android code snippets that I will need to go back to from time to time.

I’m sharing the codes we need to show an Android confirm dialog to prompt the user to click “yes” or “no”, or in my case, “OK” or “Cancel”.

The following code for Android confirm dialog is in my MainActivity.java file:

Code snippet for “Android confirm dialog”

Run this on your Android phone or emulator. When you click OK or Cancel, you’ll see logs on Android Studio’s logcat “OK” or “Cancel”, whichever button you click.

The above code was adapted from (Android) Simple confirm dialog at Jymden.com, and then modified to work on my MainActivity.java.

By the way, I use Android Studio version 1.4 on Windows 7.

Related Posts:

Posts that may be related to "Android confirm dialog box with OK and Cancel button":

Catzie

An odd human being who happens to have a variety of ever-changing interests, but right now they are programming, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert/drink flavors, obsessing about finding out how some things works, automation, anime, video games... Ran online dessert shops Cookies PH and Catzie's Cakery in her past life.

Leave a Reply

Your email address will not be published. Required fields are marked *