Android的:列表preference隐藏/禁用值 [英] Android: ListPreference hide/disable value
问题描述
我基于XML(条目和entryValues)。
I'm generating a listPreference dialog based on xml (entries and entryValues).
<string-array name="listArray">
<item>Title (A-Z)</item>
<item>Title (Z-A)</item>
<item>Visits (default)</item>
<item>Date</item>
<item>Manual</item>
</string-array>
<string-array name="listValues">
<item>titleASC</item>
<item>titleDESC</item>
<item>visitsSort</item>
<item>createSort</item>
<item>manualSort</item>
</string-array>
我想隐藏/禁用某些条目(例如:手动)。根据其他一些参数
I want to hide/disable some of the entries (for example: Manual) based on some other parameters.
我的理解应该是这样域内:
I understand it should be inside this scope:
Preference sorted = (Preference) findPreference(OPT_SORT);
sorted.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (params) {
What should i put here to hide/disable some of the entries?
}
return true;
}
});
感谢您!
修改
我发现最好的解决办法是加载一组不同的条目和EntryValues的。
在preference类(的onCreate):
Best solution I found is to load a different set of Entries and EntryValues. On Preference class (onCreate):
ListPreference sortBy = (ListPreference) findPreference(OPT_SORT);
if (isTabletDevice()) {
sortBy.setEntries(getResources().getStringArray(R.array.HClistArray));
sortBy.setEntryValues(getResources().getStringArray(R.array.HClistValues));
}
希望这可以帮助任何人! :)
Hope this helps anyone! :)
推荐答案
据我所知,目录preference
不支持这一点。你也许可以创建自己的目录preference
在您使用自定义的适配器
并注明子类,项目并没有开启。
AFAIK, ListPreference
does not support this. You might be able to create your own subclass of ListPreference
where you use a custom Adapter
and indicate which items are and are not enabled.
这篇关于Android的:列表preference隐藏/禁用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!