views:

185

answers:

1

I'm setting out to create a settings activity for my app. I've defined a PreferenceActivity with a nice layout including a ListPreference object for the user to select a bluetooth device. I'm having trouble dynamically populating the list.

I would like to populate ListPreference with values from an array adapter (which I'll create and populate with relevant bluetooth device names).

If this were a spinner View, I could just call setAdapter(). However with the ListPreference object I can't figure out how to attach an adapter (findviewByID won't cast from View To ListPreference, so I can't even get a handle to the object).

I would like to attach an adapter and then populate the adapter with values, which in turn would populate the ListPreference with values.

A: 

ListPreference doesn't work with adapters, it works with strings. See setEntries() and setEntryValues()

To get at your ListPreference, call findPreference() on your PreferenceActivity. Cast the Preference you get back to ListPreference.

CommonsWare
Nice, nice. Thank you!
Brad Hein