How do I display an alert dialog on Android?

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

    public void showSimpleDialog(View view) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setCancelable(false);
        builder.setTitle("AlertDialog Title");
        builder.setMessage("Simple Dialog Message");
        builder.setPositiveButton("OK!!!", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                //
            }
        })
        .setNegativeButton("Cancel ", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
    
            }
        });
    
        // Create the AlertDialog object and return it
        builder.create().show();
    }
    

    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/.

提交回复
热议问题