Ihor DIM
Ihor DIM

Reputation: 689

Android: preference activity. Dependency by list values

How to set dependency by the ListPreference values?

Upvotes: 2

Views: 2341

Answers (2)

user658042
user658042

Reputation:

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.

Upvotes: 5

Snicolas
Snicolas

Reputation: 38168

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

Upvotes: 1

Related Questions