Articles → ANDROID → Alertdialog In Android
Alertdialog In Android
What Is Alertdialog?
Regions Of Alertdialog
- Title
- Content area (where message is displayed)
- Action buttons (Maximum 3)
Click to Enlarge
Example
public void ButtonClicked(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This is the title");
builder.setMessage("This is the message");
builder.setCancelable(false);
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(EditTextDemo.this, "Ok Button Clicked", Toast.LENGTH_LONG).show();
}
});
builder.show();
}
Click to Enlarge