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
JavaScript
x
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