2

我用 OnMultiChoiceClickListener 创建了一个 AlertDialog,我想在用户选择第四个选项时取消选中复选框,即我希望用户只选择 3 个项目。

代码:

 protected void showSelectColoursDialog() {
            boolean[] checkedColours = new boolean[colours.length];
            int count = colours.length;

            for(int i = 0; i < count; i++)
                checkedColours[i] = selectedColours.contains(colours[i]);

            DialogInterface.OnMultiChoiceClickListener coloursDialogListener = new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {

    //               ((AlertDialog) dialog).getListView().setItemChecked(which,false);

                    if(selectedColours.size()>2){

 // Here I wants to uncheck Checkbox,but the below line is not working for me.

                        ((AlertDialog) dialog).getListView().setItemChecked(which,false);

                        alertMessage();

                    }
                    else{

                    if(isChecked)
                        selectedColours.add(colours[which]);
                    else
                        selectedColours.remove(colours[which]);

                    }
                    onChangeSelectedColours();
                }
            };
4

0 回答 0