2

How to set dependency by the ListPreference values?

Ihor DIM
  • 689
  • 1
  • 10
  • 22

2 Answers2

5

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.

  • 1
    If you want to see some code for this approach, check this answer: http://stackoverflow.com/questions/3969807/listpreference-dependency – AlvaroSantisteban Aug 21 '13 at 18:47
1

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

Snicolas
  • 37,840
  • 15
  • 114
  • 173