Question

http://developer.android.com/reference/android/preference/Preference.html#attr_android:dependency

if I want my list to be dependent from other check preference named on_off I can do this

<ListPreference
    android:defaultValue="100"
    android:dependency="on_off"
    android:dialogTitle="text"
    android:entries="@array/display_values"
    android:entryValues="@array/entry_values"
    android:key="preferences_text"
    android:summary="text"
    android:title="text" />

and every time when the check preference on_off have value false this list preference will be disabled.

But what If I want everytime when on_off is true the list preference to be disabled ? I need something like logical NOT for the android:dependency

is this possible ?

Was it helpful?

Solution

In preference XML, set android:disableDependentsState attribute of the "on_off" CheckBoxPreference to true. E.g.:

<CheckBoxPreference
    android:disableDependentsState="true"
    android:key="on_off"
    android:summaryOff="Dependent is enabled"
    android:summaryOn="Dependent is disabled"
    android:title="Checkbox that disables its dependents state in reverse manner" />

OTHER TIPS

You can implement it in the code:

chb = (CheckBoxPreference) findPreference("chb");
list  = (ListPreference) findPreference("list");    
chb.setOnPreferenceClickListener(new OnPreferenceClickListener() {
      public boolean onPreferenceClick(Preference preference) {
        list.setEnabled(!chb.isChecked());
        return false;
      }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top