I am trying to fill up my ListPreference from within my Activity rather than have the array stored in xml. However I am finding this problematic. I may be setting up my preferences wrong. I have access to my ListPreference however filling the content dynamically I can't seem to get. I have looked at this post. Is it possible to load ListPreference items from an adapter? but I can't seem to figure it out from this.
I am trying to occupy the ListPreference with Strings from a List of objects.
This is what I have so far:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
SharedPreferences settings = getSharedPreferences(LUAS_TIMES_PREF, 0);
ListPreference lp = (ListPreference)findPreference("station_pref");
}
Not much but how can I fill this list preference with my own list?
Thanks in advance.
It should be as simple as:
lp.setEntries(new String [] {"A Man", "A Plan"}); // set displayed text
lp.setEntryValues(new String [] {"a_man", "a_plan"}); // set associated values
Extrapolate as required :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.