2

I am displaying a list with checkboxes in a dialog. The list looks something like-

Item 1

Item 2

All

with a checkbox beside each item. Now the requirements is- If Item 1 or Item 2 or both are already checked, and All is selected, Item 1 & 2 should be unchecked.

To accomplish this, I implemented DialogInterface.OnMultiChoiceClickListener 's onClick listener.

public void onClick(DialogInterface dialog, int which, boolean isChecked)
{
  if(which == 2 && isChecked)
  {
    ((AlertDialog)dialog).getListView().setItemChecked(0, false);
    ((AlertDialog)dialog).getListView().setItemChecked(1, false);
  }
}

But this does not work. I even tried invalidating the listview by calling Invalidate() & InvalidateViews(), but no success.

Any help will be really appreciated.

Thanks,

Akshay

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
Akshay
  • 21
  • 1
  • 2

1 Answers1

0

If I understand correctly, the checkboxes are in a list. There's been a question with the opposite situation: trying to uncheck all boxes. The solution seems to be to call

adapter.notifyDataSetChanged()

Here is the link to that question: Uncheck all checkboxes in a custom ListView

EDIT: Okay, I'll try again :-) Found another question about it: android: Refresh ListView using ListAdapter and SimpleCursorAdapter Hope this helps! :-)

Community
  • 1
  • 1
pecka85
  • 752
  • 7
  • 21
  • Thanks pecka85! Yes, the checkboxes are in a list, which is in a dialog. But the dialog's adapter is a ListAdapter which does not have a method notifyDataSetChanged. This method is provided by ArrayAdapter. – Akshay Apr 12 '11 at 12:01
  • Thanks a lot Pecka85! I was also expecting this to work, but it didn't. I am sure this has something to do with the list being in a dialog. Thanks for trying! – Akshay Apr 12 '11 at 14:56