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

A Filipino programmer with a variety of interests such as baking, singing, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert flavors, obsessing about finding out how some things works, board games, anime, video games, and forgetting things that usually go in her long list of interests. Running small-time online dessert shops Cookies PH and Catzie's Cakery.

Leave a Reply

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