views:

37

answers:

1

I want to disable some items in ListView which is in the AlertDialog.

How may I do it?

+1  A: 

Supply your own custom ListAdapter to the AlertDialog.Builder via setAdapter(). You can then override areAllItemsEnabled() and isEnabled() to enable/disable whatever you want.

CommonsWare
I want to dynamically disable some items, so I have to put some code in the onPrepareDialog method, how to change the item status at that moment?
Chris
@Chris: in `onPrepareDialog()`, call `makeTheseGoAwayPlease()` on your custom `Adapter`, which stores that information and uses it in its implementation of `isEnabled()`.
CommonsWare
Beside that, I want inital some selected items, so can I do this in the onPrepareDialog() ? How ?
Chris
@Chris: With Java code. You put the checkbox there -- you check it when it needs to be checked. If you were not using `setAdapter()`, you could use `setMultiChoiceItems()` and simplify this, but then you cannot have disabled entries. In all likelihood, this should not be an `AlertDialog` -- please consider using a dialog-themed activity instead.
CommonsWare