I created an AlertDialog with checkbox items using setMultiChoiceItems(). I added a setPositiveButton() and setNegativeButton() to the Dialog.
When I press the positive button, I want to iterate through the list of items in the Dialog and determine if each one is checked or not. But it doesn’t appear there is any obvious way to do this.
I can get the list of items from this:
alertDialog.getListView().getItemAtPosition(n);
but I can’t checked if the item isChecked() or anything like that. About all I can do it print out the Text using .toString().
The only other way to do what I want, is to use the onMultiChoiceClickListener().onClick() to listen for when an item is checked, and then determine which item is clicked and if it’s checked or not. I then need to store this info in an array or list and then when the positive button is pressed, I need to refer to this array to determine which is checked and which is not. I know that this method will work, but is there a programmatic way to check if an item is checked or not after the fact?
I found my answer. I was just looking for the wrong method.
Solution
alertDialog.getListView().isItemChecked(position);Update. This is buggy
I spoke too soon. I think I discovered an Android bug with this method. If you have a high number of items in your list, to the point that the list is scrollable and you have to scroll down the list to see them, items come back as being UNCHECKED even if they are checked by default if the item has not scrolled onto the screen yet. I reported it here.