Friday, March 6, 2015

Display list of clickable items on Alert dialog

Display a simple list of clickable items on a alert dialog.
new AlertDialog
  .Builder(getApplicationContext())
  .setTitle("Actions")
  .setItems(new String[]{
    "Item #1",
    "Item #2",
    "Item #3"
  }, new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialogInterface, int i) {
         switch (i) {
           case 0 : // do something
             break;
           case 1 : // do something
             break;
           case 2 : // do something
             break;
         }
      }
    })
  .create()
  .show();

No comments:

Post a Comment