0

I am using DialogFragment with multichoice checkboxes to allow the user to pick a number of options. I have a Hashmap to which selections are added or removed depending on whether on item is selected when it is clicked - see below. This works fine.

When the user re-opens the Fragment the state of the Dialog is preserved and the items that were previously checked are shown as expected - good so far. However I'd like to know how to read the state of these and add them to my HashMap so that they are returned along with any that are picked up by Listener class. I'm sure this is simple, but I can't find an example.

I've had a look through the API Reference but I can't find an obvious method that provides this.

Thanks in advance.

public class DialogSelectionClickHandler implements
  DialogInterface.OnMultiChoiceClickListener {
  public void onClick(DialogInterface dialog, int clicked,
                      boolean selected) {
    if (selected) {
      // write to a hashmap
      groupSelectHash.put(groups[clicked].toString(), "");
    }
    else
    {
      // remove from hashmap
      groupSelectHash.remove(groups[clicked].toString());
    }
    Log.i( "DialogTest", "groupSelectHash" + groupSelectHash.toString());

  }
}
A--C
  • 36,351
  • 10
  • 106
  • 92
Darnst
  • 91
  • 1
  • 7
  • Have you tried to findViewById and then check if it is checked? – Lieuwe Jan 08 '13 at 20:46
  • The code I am using is very similar to this post (http://stackoverflow.com/questions/13858974/custom-dialog-with-setmultichoiceitems). The presentation of the items in the list is pretty opaque, i.e. I'm not using a custom layout and the options are dynamically populated when the state is maintained. How do I iterate/loop over the options (maybe using findViewById or similar) to pick up what is selected when the dialog is re-presented? Wha is the container for the items in the list? Also is there a mechanism similar to onPrepareDialog as with the deprecated API? – Darnst Jan 09 '13 at 09:17

0 Answers0