Search code examples
androidpreferenceactivity

Android: preference activity. Dependency by list values


How to set dependency by the ListPreference values?


Solution

  • 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.