Hi,
Actually, dialog remembers previous state is good but it always does even
though you press OK button or CANCEL button.
When creating a dialog, i use an array to store checkbutton's states. So
when user presses CANCEL, i do not update this state array.
Ex: At first time, when i create dialog, i initial new_state_array
={true,true,true}.
After that user unchecked first and second checkbox item, then pressing
CANCEL.
It is great if dialog still displays 3 checkbox item in checked state on
next time but it only display third checkbox item in checked state.

Please see my code below and give me advices to solve that problem.
**********************************************************************************
.setMultiChoiceItems(R.array.select_map_mod,
                        new_state_array,* /*<--- So when recreate Dialog,it
must update state but it seems to me that it doesnot work except the first
time**/
                        new DialogInterface.OnMultiChoiceClickListener()
                        {
                            public void onClick(DialogInterface dialog, int
whichButton,
                                    boolean isChecked)
                            {
                                new_state_array[whichButton] = 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 */
                        for(int i=0;i<3;i++) old_state_array[i] =
new_state_array[i];
                    }
                })
.setNegativeButton(R.string.alert_dialog_cancel, new
DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int
whichButton)
                    {
                        /* User clicked No so do some stuff */

                        for(int i=0;i<3;i++) new_state_array[i] =
old_state_array[i];
                    }
                })
**********************************************************************************
On Mon, Apr 27, 2009 at 1:22 PM, Glen Humphrey
<glendon.humphr...@gmail.com>wrote:

>
> You can override onPrepareDialog to reset the checkboxes.
>
> On Apr 9, 7:16 am, DavidG <dgu...@gmail.com> wrote:
> > I'd like to have a dialog box which prompts the user to select from
> > various checkboxes, then confirm "Ok" or "Cancel". I have this
> > working, but my only issue is the dialog always retains the previous
> > checkbox selection state from the last time the dialog was shown. I'd
> > like to always force the checkboxes to be unchecked (false) every
> > time. Is there a way to accomplish this?
> >
> > protected Dialog onCreateDialog(int id) {
> >         switch (id)         {
> >         case DIALOG_OPTION:
> >             return new AlertDialog.Builder(MyApp.this)
> >             .setTitle(R.string.select_option_title)
> >             .setMultiChoiceItems(R.array.select_option,
> >                     null,
> >                     new DialogInterface.OnMultiChoiceClickListener() {
> >                         public void onClick(DialogInterface dialog,
> > int whichButton, boolean isChecked) {
> >                             /* Do whatever with checked buttons */
> >                         }
> >                     })
> >             .setPositiveButton("OK", new
> > DialogInterface.OnClickListener() {
> >                 public void onClick(DialogInterface dialog, int
> > whichButton) {
> >                         /* User clicked Yes so do some stuff */
> >                         /* Is there a way to reset the checked buttons
> state
> > to false from here? */
> >                 }
> >             })
> >             .setNegativeButton("Cancel", new
> > DialogInterface.OnClickListener() {
> >                 public void onClick(DialogInterface dialog, int
> > whichButton) {
> >                     /* User clicked No so do some stuff */
> >                     /* Is there a way to reset the checked buttons
> > state to false from here? */
> >                 }
> >             })
> >            .create();
> >      }
> >      return null;
> >
> > }
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to