【问题标题】:i can't display the list in a dialog with setMultiChoiceItems in Android我无法在 Android 中使用 setMultiChoiceItems 的对话框中显示列表
【发布时间】:2012-07-27 12:57:51
【问题描述】:

我有一个方法返回 CharSequence[] 并且不为空(使用日志检查)但未显示在对话框中。 我必须初始化 boolean[] 数组吗? 我没有看到任何错误,所以也许我想念一些东西。 我的代码是:

dbManager.open();
final CharSequence[] usrCats = dbManager.getUserCreatedCategories();

dbManager.close();
final boolean[] selections = new boolean[usrCats.length];

   alert = b.setTitle(R.string.remove_category)
            .setMessage(R.string.delete_categories_msg)
            .setMultiChoiceItems(usrCats, selections, new DialogInterface.OnMultiChoiceClickListener(){
             public void onClick(DialogInterface dialog, int which, boolean isChecked){
            }
        })

            .setPositiveButton("Create", new DialogInterface.OnClickListener(){
             public void onClick(DialogInterface dialog, int which){
            }       
    }).create();
  }

【问题讨论】:

  • 对话框和按钮显示但没有列表

标签: android dialog


【解决方案1】:

我不知道为什么,但 setMessagesetMultiChoiceItems 不能一起工作。当我删除setMessage 时,列表显示得很好。

【讨论】:

  • 确实很奇怪。调试了几个小时没有运气。这就像一个魅力 - 谢谢。
  • 我猜如果我们通过 setMessage 它会认为这个对话框不是一个列表对话框。
【解决方案2】:
Dialog _dialog;
 _dialog = new Dialog(classname.this);
            _dialog.setTitle("Title");
            _dialog.setContentView(R.layout.dialoglist);
            ListView _output = (ListView) _dialog
                    .findViewById(R.id.dialoglistid);
            _output.setAdapter(new exmpleadaptor());
            // _output.setOnItemClickListener(classname.this);
            //can use multichoice list option
            _dialog.show();
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多