tags:

views:

40

answers:

2

Hi,

How can I create a dialog with each dialog item being a label and then a checkbox?

And when user click 'ok' to the dialog, I can tell in my code which on of the dialog item has been checked?

Thank you.

A: 

You might be interested in RadioGroup. The Android API demos have an example of using it here.

Not quite a checkbox, but a radio group allows you to click on the radio button from the list, and keep track of which one was selected. I have used one to do what you described (although I used an Activity instead of a Dialog, and used android:theme="@android:style/Theme.Dialog" in my manifest to make my pretend dialog activity -look- like a Dialog).

The biggest problem though, is that RadioGroup only allows you to choose -one- item. So if you want to be able to select multiple items, then it will not work.

Aurora
+1  A: 

Alertdialog.Builder setMultiChoiceItems(..) is an option. Link.

alex
`AlertDialog.Builder` is likely what you want. `setSingleChoiceItems` will cover you if you only want the user to select one item.
adamp