如何取消选中项AlertDialog(setMultiChoiceItems)? [英] How uncheck items in AlertDialog (setMultiChoiceItems)?

查看:730
本文介绍了如何取消选中项AlertDialog(setMultiChoiceItems)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想清楚所选项目的时候总来选择,我做如下,但不工作三个项目...

  AlertDialog.Builder建设者=新AlertDialog.Builder(本);
        builder.setTitle(getResources()的getText(R.string.escolhaArquivosBaixados));
        builder.setMultiChoiceItems(项目,选择新DialogInterface.OnMultiChoiceClickListener(){

            @覆盖
            公共无效的onClick(DialogInterface对话,诠释它,布尔器isChecked){
                //
                诠释计数= 0;
                的for(int i = 1; I< selected.length;我++){
                    //
                    如果(选择[​​我]){
                        算上++;
                    }
                    如果(计数== 3){
                        //这里进入,但没有任何反应
                        ((AlertDialog)对话框).getListView()setItemChecked(其中假)。
                        打破;
                    }
                }
            }

        });
 

解决方案

眼看Jorgesys答案在此<一个href="http://stackoverflow.com/questions/1640799/alertdialog-multichoiceitems-listener-problems">question我意识到什么是缺少在我的code,必须改变布尔列表了。

 选择[它] = FALSE;
        ((AlertDialog)对话框).getListView()setItemChecked(其中假)。
 

I'd like to clear selected items when the total came to three items selected, I am doing as follows but is not working ...

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getResources().getText(R.string.escolhaArquivosBaixados));         
        builder.setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                //                  
                int count = 0;                  
                for(int i = 1; i < selected.length; i++){
                    //
                    if (selected[i]){
                        count++;
                    }
                    if (count == 3){
                        //enter here but nothing happens
                        ((AlertDialog) dialog).getListView().setItemChecked(which, false);   
                        break;
                    }
                }                   
            }

        });

解决方案

Seeing Jorgesys answer in this question I realized what was missing in my code, is necessary to change the boolean list too.

        selected[which] = false;
        ((AlertDialog) dialog).getListView().setItemChecked(which, false);

这篇关于如何取消选中项AlertDialog(setMultiChoiceItems)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆