How can I add a third button to an Android Alert Dialog?
When you are creating the dialog, add something like this to the builder:
builder = new AlertDialog.Builder(context);
builder.setTitle("Test");
builder.setIcon(R.drawable.icon);
builder.setMessage("test");
builder.setPositiveButton("Call Now",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
builder.setNeutralButton("Setup",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
context.startActivity(new Intent(context, Setup.class));
//dialog.cancel();
}
});
builder.setNegativeButton("Exit",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
builder.create().show();
This code snippet should help explain the three different buttons you can use:
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Dialog Button");
alertDialog.setMessage("This is a three-button dialog!");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Button 1 Text", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//...
} });
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Button 2 Text", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//...
}});
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Button 3 Text", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//...
}});