Last Updated: February 25, 2016
·
383
· gangrenagastrit

The most simple dialog

An example of the most simple dialog box with a single button.

Make OnClick method:

DialogInterface.OnClickListener doNothing = new DialogInterface.OnClickListener()
{
    public void onClick(DialogInterface arg0, int arg1) 
    {
        // For example, complete the Activity
        finish();
    }
};

Show dialog:

new AlertDialog.Builder(this)
.setMessage("YOUR_MESSAGE")
.setNeutralButton("BTN_CAPTION", doNothing)
.setCancelable(false)
.create().show();