开发者

AlertDialog.Builder: No items for checkboxes are shown

I have a problem with the alertdialog.builder in the following code:

    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 di开发者_StackOverflow中文版alog, 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();   
 }

The three items and checkboxes are not displayed, there is just one white line between the title bar and the Apply-Button. Does anybody know why this does not work?


Remove the builder.setMessage(fMessage) line and it'll work :)

setMessage is only used for when you want to display a text message. If you use it in conjunction with setMultiChoiceItems or setItems it appears to make the builder go into an undefined state.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜