Skip to content
Advertisement

How to set alert dialog box in android java? [closed]

How to set alert dialog box in android java?

How to set alert dialog box in android java?

Advertisement

Answer

A normal alert Dialog would look something like this

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title of the alert dialog");
builder.setMessage("Message to be displayed in the alert dialog");
builder.setPositiveButton("Positive Button", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // Code to be executed when the positive button is clicked
    }
});
builder.setNegativeButton("Negative Button", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // Code to be executed when the negative button is clicked
    }
});

AlertDialog alertDialog = builder.create();
alertDialog.show();

You can customize this more. Please look into the AlertDialog class in the Android documentation

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement