How do I display an alert dialog on Android?

后端 未结 30 3282
清歌不尽
清歌不尽 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:38

    Try this code:

    AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
    builder1.setMessage("Write your message here.");
    builder1.setCancelable(true);
    
    builder1.setPositiveButton(
        "Yes",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
    
    builder1.setNegativeButton(
        "No",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
    
    AlertDialog alert11 = builder1.create();
    alert11.show();
    

提交回复
热议问题