程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了更改 Multichoice AlertDialog大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决更改 Multichoice AlertDialog?

开发过程中遇到更改 Multichoice AlertDialog的问题如何解决?下面主要结合日常开发的经验,给出你关于更改 Multichoice AlertDialog的解决方法建议,希望对你解决更改 Multichoice AlertDialog有所启发或帮助;

我一直在尝试实现一个多选警报对话框,在大多数情况下,一切都清晰易懂,但警报对话框从布尔数组中获取项目的状态,并且所有项目都设置为 true。如果在警报对话框中选中它,我无法弄清楚如何更改数组中项目的状态。

 private voID showcategorySELEctionDialog() {
        // Prepare the dialog by setTing up a Builder.
        final String selectiontitle = "Show on map: ";
        AlertDialog.builder builder = new AlertDialog.builder(getActivity());
        builder.settitle(SELEctiontitlE);

        final String[] categorIEs = new String[]{"CamPing grounds","Abandoned places","Nature areas","Lookout Points"};
        
        // Find the current map type to pre-check the item represenTing the current state.
        Boolean[] checkedItems = new Boolean[]{
                true,true,true
        };

        // Add an OnClickListener to the dialog,so that the SELEction will be handled.
        builder.setMultiChoiceItems(

                categorIEs,checkedItems,new DialogInterface.onMultiChoiceClickListener() {

                    @OverrIDe
                    public voID onClick(DialogInterface dialog,int which,Boolean ischecked) {
                      //check which item is clicked and if it was true then set it as false.
                        if (ischecked && checkedItems[which] == truE){
                            checkedItems[which]= false;
                        }else{
                      //If item was clicked and the value was false then set it as true.
                            checkedItems[which] = true;
                        }
                    }
                }
        );
        builder.setPositivebutton("OK",new DialogInterface.onClickListener() {
            @OverrIDe
            public voID onClick(DialogInterface dialog,int which) {
                dialog.dismiss();
            }
        });
        // Build the dialog and show it.
        AlertDialog categoryDialog = builder.create();
        categoryDialog.setCanceledOntouchOutsIDe(true);
        categoryDialog.show();
    }

这个当前的解决方案不会改变值,我的假设是我以不正确的方式处理数组,但我不确定正确的方式会如何。

解决方法

由于您想在检查数组时更改元素的值,因此您可以尝试将该值设置为与通过 cAnnot read property paginationoption of undefined 方法传递的 ischecked 变量相等。

检查下面的代码:

onClick()

大佬总结

以上是大佬教程为你收集整理的更改 Multichoice AlertDialog全部内容,希望文章能够帮你解决更改 Multichoice AlertDialog所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:更改