【发布时间】:2011-06-21 12:38:35
【问题描述】:
我正在尝试从我的 Activity 中填充我的 ListPreference,而不是将数组存储在 xml 中。但是我发现这有问题。我可能设置错了我的偏好。我可以访问我的 ListPreference 但是我似乎无法动态填充内容。我看过这个帖子。 Is it possible to load ListPreference items from an adapter? 但我似乎无法从中弄清楚。
我正在尝试使用对象列表中的字符串来占用 ListPreference。
这是我目前所拥有的:
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");
}
不多,但我怎样才能用我自己的列表填充此列表首选项?
提前致谢。
【问题讨论】:
-
为什么不想将首选项列表存储在 XML 中?
-
我有一个 JSON 对象的原始资源,我读入并填写了一个列表。然后,我想使用该列表来占用 ListPreference,因此如果用户偏好启动应用程序来显示默认对象,它将显示默认对象。
标签: java android listpreference