I want to display a dialog/popup window with a message to the user that shows "Are you sure you want to delete this entry?" with one button that says 'Delete'. When Delete
is touched, it should delete that entry, otherwise nothing.
I have written a click listener for those buttons, but how do I invoke a dialog or popup and its functionality?
This is a basic sample of how to create an Alert Dialog :
Just be careful when you want to dismiss the dialog - use
dialog.dismiss()
. In my first attempt I useddismissDialog(0)
(which I probably copied from some place) which sometimes works. Using the object the system supplies sounds like a safer choice.Also check out my blog on Dialogs in Android, you will find all the details here: http://www.fahmapps.com/2016/09/26/dialogs-in-android-part1/.
Nowadays it's better to use DialogFragment instead of direct AlertDialog creation.
you may try this way also, it will provide you material style dialogs