Dialog的使用:onCreateDialog showDialog

Dialog的使用:onCreateDialog() showDialog()

onCreateDialog()函数:

protected Dialog onCreateDialog(int id) {
  switch (id) {
  case 1: {
   return new AlertDialog.Builder(this).setIcon(R.drawable.icon)
     .setTitle(R.string.menu_group_longclick).setItems(
       R.array.menu_group_longclick_array,
       new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
          int which) {
         onMenuItemClick(
           Globals.DIALOG_GROUPS_LONGCLICK,
           which);
         // removeDialog(1);
         //建议使用,清楚缓存
        }
       }).create();
    }
   case 2:{
   
    return new AlertDialog.Builder(this).setIcon(R.drawable.icon)
     .setTitle(R.string.menu_group_longclick).setItems(
       R.array.menu_group_longclick_array,
       new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
          int which) {
         onMenuItemClick(
           Globals.DIALOG_GROUPS_LONGCLICK,
           which);
           //建议使用,清楚缓存
         // removeDialog(2);
        }
       }).create();
   }
  }
}

调用函数:

showDialog(1);

你可能感兴趣的:(Dialog的使用:onCreateDialog showDialog)