AlertDialog with Multiple Options
Hi Guys, At times you may require to show multiple options in a dialog on Acitivty. So user can select any one option. here is the simple code to display with AlertDialog with Multiple Options
CharSequence options[] = new CharSequence[] {"Call", "SMS", "Email"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setTitle("Select your option:");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on options[which]
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//the user clicked on Cancel
}
});
builder.show();
You can see as shown below
Cheers …:)
You may be also interested in
2 thoughts on “Display AlertDialog with Multiple Options”
hey there,
How to add icons before these options?
Hi Tejpal, You need to implement custom dialog for it. This post uses default dialog methods.