开发者

Programatically unchecking items in a dialog on Android

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)dia开发者_开发技巧log).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


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! :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜