简体   繁体   中英

Android: preference activity. Dependency by list values

How to set dependency by the ListPreference values?

As already pointed out by Snicolas, the depency xml feature only checks for a boolean state (= if the referenced key is true or a value is set in it). If enabled, you can use this preference, if it is not, you can't.

To archieve a depency when a certain ListPreference entry is selected, you have to write some logic in code. I'd solve this by using a OnSharedPreferenceChangedListener . When the preference/key thats associated with your ListPreference changes, test to which value it has changed. If it now has one that enables or disables your preference, use Preference.setEnabled() to change it.

Dependency means that "If the other Preference is not set or is off, this Preference will be disabled."

It's got nothing to do with values.

REgards, stéphane

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM