I want to put a dialog on the screen on Android.

Asked 2 years ago, Updated 2 years ago, 151 views

I'm going to create a dialog with the delete button printed on it, "Are you sure you want to delete this?"

If you press the delete button, the data will be deleted, and if you don't, nothing will happen, but I made this button click listener, but I can't add it to the dialog... What do I do?

android android-dialog

2022-09-22 22:34

1 Answers

new AlertDialog.Builder(context)
    .setTitle("Delete entry")
    .setMessage ("Are you sure you want to delete this?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
                    // Click this button to proceed with deletion 
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
                    // Nothing's happening 
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();

Try applying this.


2022-09-22 22:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.