Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog MultiChoiceItems Listener problems

I am currently using the AlertDialog.builder to create a multichoice list for the user (checkboxes). This works great, except we want one of the buttons to deselect all of the others in the list.

builder.setMultiChoiceItems(list, checked,
  new DialogInterface.OnMultiChoiceClickListener() {
   public void onClick(DialogInterface dialog,
     int item, boolean isChecked) {

    if(item == ANY_ITEM_BUT_0)
    {

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

    }
   }
  });

When using "true" it will successfully check the box, but when using false it does not uncheck it (unless i have manually set it to true before hand.) Is there a separate listener I should be using to detect when a user clicks these? It seems to me that there are two checkmarks set, one by the "setItemChecked(0, true);", and one by actually selecting it.

This has been driving me nuts for a couple days now, any help would be greatly appreciated.

like image 708
tsmith Avatar asked Oct 28 '09 23:10

tsmith


1 Answers

OH!!! I forget it to ensure deselect you must change checked to null ;), I had the same issue.

    builder.setMultiChoiceItems(list, null, new DialogInterface.OnMultiChoiceClickListener() {
...
like image 104
Jorgesys Avatar answered Sep 25 '22 19:09

Jorgesys