Android AlertDialog多选项

时间:2015-07-23 09:49:32

标签: android android-alertdialog multichoiceitems

我为用户提供了一个名为选择日期的按钮的活动 当用户点击按钮时,它会显示一个警告对话框,用于选择星期几

现在我想要用户选择多天

然后先前选中的复选框将显示在检查位置并保持取消选中位置

2 个答案:

答案 0 :(得分:2)

Here是一个不错的库,我将它用于我的项目。 enter image description here

第1步:

将这些行添加到build.gradle文件

  dependencies {
compile 'com.afollestad:material-dialogs:0.7.7.0'
}

repositories 
maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
}

第2步: 在要显示对话框的代码中添加以下内容:

new MaterialDialog.Builder(this)
    .title(R.string.title)
    .items(R.array.items)
    .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {
        @Override
        public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
            /**
             * If you use alwaysCallMultiChoiceCallback(), which is discussed below,
             * returning false here won't allow the newly selected check box to actually be selected.
             * See the limited multi choice dialog example in the sample project for details.
             **/
             return true;
        }
    })
    .positiveText(R.string.choose)
    .show();

项目(R.array.items) - 应该是资源中字符串值的数组。

P.S。请阅读该库的文档,非常简单明了)

enter image description here

答案 1 :(得分:0)

也许你可以看一下Android标准。 Dialogs

它还向您展示了如何创建自定义对话框。他们有一个带复选框的列表示例

相关问题