How to generate dynamic listPreference in android? I want to get all wifi access points and make a list using in preference Activity(i.e. make a list using listpreference).
This minimalist technique is for both environments.
In preferences.xml
In PreferenceFragment.onCreate()
addPreferencesFromResource(R.xml.preferences);
expand_xyzzy((ListPreference)findPreference("xyzzy"));
Elsewhere
public static Preference expand_xyzzy (ListPreference pref) {
if (pref == null) return pref;
pref.setEntries(new String["one","two","three];
pref.setEntryValues(new String["0","1","2"]);
return pref;
}
Notes:
(a) XML is self-documenting and perhaps a better choice than dynamic preference creation.
(b) Starting your PreferenceFragment by NOT using PreferenceActivity easily lets you do this: