我如何获得我的AlertDialog的setMultiChoiceItems项目? [英] How do i obtain the setMultiChoiceItems items from my AlertDialog?

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

问题描述

我使用的是从apidemos以下code ..

I'm using the following code from the apidemos..

        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIcon(R.drawable.ic_popup_reminder)
            .setTitle(R.string.alert_dialog_multi_choice)
            .setMultiChoiceItems(R.array.select_dialog_items3,
                    new boolean[]{false, true, false, true, false, false, false},
                    new DialogInterface.OnMultiChoiceClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton,
                                boolean isChecked) {

                            /* User clicked on a check box do some stuff */
                        }
                    })
            .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Yes so do some stuff */
                }
            })
            .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked No so do some stuff */
                }
            })
           .create();

/ *用户点击的是这样做的一些东西* / ,我不喂的变量器isChecked。但是,我给在器isChecked的 / *用户点击一个复选框做一些东西* / 部分..很明显,我不想更新我的复选框,单击共享preFS,如果用户点击取消..

Under /* User clicked Yes so do some stuff */, i'm not fed the isChecked variable.. however, I am given isChecked in the /* User clicked on a check box do some stuff */ section.. Obviously i don't want to update my SharedPrefs on checkbox click, in case the user hits cancel..

因此​​,我怎么得到的 setPositiveButton 的onClick的checkboxs和价值观?

So how do I get the checkboxs and values on the setPositiveButton onClick ?

感谢。

推荐答案

传入 setMultiChoiceItems引用字节[] ()

Pass a reference to byte[] in setMultiChoiceItems().

    final boolean[] booleans = {false, true, false, true, false, false, false};

然后检查布尔值 setPositiveButton()

如果你需要通过这个 AlertDialog 周围,然后扩展 AlertDialog 并创建一个字段布尔如上述1。

If you need to pass this AlertDialog around, then extend AlertDialog and have create a field boolean as described in 1.

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

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