How do I display an alert dialog on Android?

后端 未结 30 3073
清歌不尽
清歌不尽 2020-11-22 03:02

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

30条回答
  •  无人共我
    2020-11-22 03:36

    Code to delete an entry from the list

     /*--dialog for delete entry--*/
    private void cancelBookingAlert() {
        AlertDialog dialog;
        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this, R.style.AlertDialogCustom);
        alertDialog.setTitle("Delete Entry");
        alertDialog.setMessage("Are you sure you want to delete this entry?");
        alertDialog.setCancelable(false);
    
        alertDialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
               //code to delete entry
            }
        });
    
        alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    
        dialog = alertDialog.create();
        dialog.show();
    }
    

    Call above method on delete button click

提交回复
热议问题