AlertDialog.Builder:没有显示复选框的项目

时间:2010-06-21 00:06:49

标签: android alertdialog

我在以下代码中遇到了alertdialog.builder的问题:

    public void showSettingsBox(){
  final CharSequence[] items = {"Item1", "Item2", "Item3"};
  final boolean checked[] = new boolean[]{false,false,false};

  AlertDialog.Builder builder = new AlertDialog.Builder(fLabyrinthGame); 
  builder.setMessage(fMessage)
   .setCancelable(false)
   .setMultiChoiceItems(items, checked, new OnMultiChoiceClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
     CharSequence text = "Item number " + which;
     int duration = Toast.LENGTH_SHORT;

     Toast toast = Toast.makeText(fLabyrinthGame, text, duration);
     toast.show();

    }
   })
   .setPositiveButton("Apply", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
     dialog.cancel();
    }
   });
  builder.setTitle(fTitle); 
  builder.setIcon(R.drawable.icon_exclamation); 

  AlertDialog alert = builder.create(); 

  alert.show();   
 }

不显示三个项目和复选框,标题栏和应用按钮之间只有一条白线。有谁知道为什么这不起作用?

1 个答案:

答案 0 :(得分:11)

删除builder.setMessage(fMessage)行,它会工作:)

setMessage仅用于您想要显示短信的时间。如果将其与setMultiChoiceItemssetItems结合使用,则可能会使构建器进入未定义状态。