【问题标题】:AlertDialog MultipleChoice Doesn't Show ItemsAlertDialog MultipleChoice 不显示项目
【发布时间】:2016-09-14 16:34:49
【问题描述】:

我在显示 AlertDialog 中的项目时遇到问题。 我检查了代码,没关系。只有items 不显示。

这是我的代码:

//PREFERENCE CATEGORY - DIALOG
public void alertDialogPrefCat(){
    //TODO -
    String[] categories = new String[]{"Health","Universities","Scholars","Professionals",
                           "Business","Engineering","Architecture","Foundations",
                           "Charities", "Culture", "Technology","Blog", "Music",
                           "Sports","Insurance"};
    //GET CHECKED
       final boolean[] selectedCategory = new boolean[]{false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false,
                                           false
       };

    AlertDialog.Builder alertDialogCategoryPicker = new AlertDialog.Builder(this);
    final List<String> itemGet = Arrays.asList(categories);

    alertDialogCategoryPicker.setTitle("Interest: ")
                             .setMessage("Select category of org you want.")
                             .setCancelable(false)
                             .setMultiChoiceItems(categories, selectedCategory,
                             new DialogInterface.OnMultiChoiceClickListener() {
                             @Override
                             public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                selectedCategory[which] = isChecked;
                                String currentItem = itemGet.get(which);
                                Toast.makeText(MainActivity.this, currentItem, Toast.LENGTH_SHORT).show();
                                }
                             })
                             .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                                     @Override
                                     public void onClick(DialogInterface dialog, int which) {

                                     }
                             });

    AlertDialog dialogCategory = alertDialogCategoryPicker.create();
    dialogCategory.show();

}

我得到这个带有空项目的对话框。

【问题讨论】:

  • 您可以创建自己的易于处理的自定义对话框。

标签: android android-alertdialog multiple-choice


【解决方案1】:

setMultiChoiceItems()setMessage() 不能一起使用。 尝试删除.setMessage("Select category of org you want.")

参考链接: https://developer.android.com/guide/topics/ui/dialogs.html

setMultiChoiceItems and setMessage not "working" in AlertDialog

【讨论】:

  • 哇,你的权利。非常感谢!有没有办法可以通知用户?嗯.. :/
  • 是的。您可以通过为 alertdialog 创建自定义布局来通知用户。
  • 是的。将该信息也放入标题中。
猜你喜欢
  • 2012-05-29
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
  • 2022-07-27
  • 1970-01-01
  • 1970-01-01
  • 2019-12-06
  • 1970-01-01
相关资源
最近更新 更多