如何取消选中项AlertDialog(setMultiChoiceItems)?AlertDialog、setMultiChoiceItems

2023-09-12 10:31:32 作者:月亮邮递员

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

  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答案在此question我意识到什么是缺少在我的code,必须改变布尔列表了。

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

alertdialog android api 11,Android 中文 API 对话框 AlertDialog.Builder

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);