Display AlertDialog with Multiple Options

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

AlertDialog

Cheers …:)

You may be also interested in