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.
ListPreferencedoesn’t work with adapters, it works with strings. SeesetEntries()andsetEntryValues()To get at your
ListPreference, callfindPreference()on yourPreferenceActivity. Cast thePreferenceyou get back toListPreference.