I have used PreferenceActivity
to have preference in my android application. I want one preference say "pref 2" to be enabled when other preference say "pref 1" is NOT checked and "pref 2" to be disabled when "pref 1" is checked.
i.e. exactly opposite of the android:dependancy
attribute.
How can I do that?
I don't think there's any out-of-the-box solution for it, i.e. an inverted
dependancy
attribute. But there's always the click-listener:Yes it's possible to do this out of the box. Let's say you want to disable pref2 when pref1 is off
Here's the code(preference xml layout) to put in for pref1:
Here's the code(preference xml layout) to put in for pref2:
Like sigmazero13 said, by default disableDependentsState is false so you don't need to include it in the pref1 attributes.
Android CheckBox??
I am assuming you are using the Android.widget.checkBox:
Try this
GoodLUCK!!
According to the docs here, you can add an attribute to the CheckBoxPreference tag like so:
By default this is false, which means that the dependents are disabled when the checkbox is unchecked, but by setting it to true, it should have the opposite effect.