tags:

views:

63

answers:

2

In my apps preferences screen, i want to pop up a dialog that shows a list of checkbox items that are dynamically generated.

How does one do that and also, how does one get the checked values? I have made custom dialogs in the past, but for some reason my brain wont function today ...

Thanks.

A: 

The way I've done this is to create a ListView that contains rows of CheckBoxes.

private class CheckBoxListAdapter extends ArrayAdapter<CheckBoxListRowItem> {

}

To get the checked values, I call setOnCheckedChangeListener for each CheckBox. Each time it's checked, it updates the my model data (CheckBoxListRowItem). When you need to figure out which CheckBoxes are checked, you can get it from the model data, not directly from the CheckBox object (which is how I thought it should work originally).

Brandon
could you elaborate with some example code? thanks!
ekawas
I couldn't get you way to work. I am sure that it was because of something that I was missing, but each item i generated didn't have a label.
ekawas
A: 

I ended up creating an activity that extended ListActivity. Since I wanted a list of checkboxes (where 0 or more could be selected), in my

onCreate():

getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

and I listen for clicks by overriding onListItemClick().

The list adapter that I used was ArrayAdapter:

setListAdapter(
   new ArrayAdapter<String>(this, 
                            android.R.layout.simple_list_item_multiple_choice, 
                            some_string_array));
ekawas