Reputation: 218
Is there a way to make field "A" dependent of two fields "key1" and "key2"? I'm using a list of values and there are 2 options to use them and I need either one of them to "unlock" it without having to duplicate field "A". Something like this android:dependency="key1 | key2"
?
Upvotes: 0
Views: 51
Reputation: 48
If you try android:dependency="key1 | key2
your app will crash. I dont know if there is a way to do it in xml, but you can do that in code like this:
final ListPreference fieldA = (ListPreference) findPreference("fieldA");
SwitchPreference key1 = (SwitchPreference) findPreference("key1");
SwitchPreference key2 = (SwitchPreference) findPreference("key2");
key1.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue){
fieldA.setEnabled((Boolean) newValue);
return true;
}
});
key2.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue){
fieldA.setEnabled((Boolean) newValue);
return true;
}
});
Upvotes: 1