I've a checkbox and a ListPreference, I'd like disable/enable ListPreference by checkbox. I read a lot and I found is possible only using java (and not by xml). Is it correct? Now, after read the value of "checkboxPref" (boolean true/false) I don't how do.
SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(this);
listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String listpref) {
CheckboxPreference = prefs.getBoolean("checkboxPref", true);
} };
prefs3.registerOnSharedPreferenceChangeListener(listener);
preferences.xml:
<CheckBoxPreference
android:title="Notifify"
android:defaultValue="true"
android:key="checkboxPref" />
<ListPreference
android:entries="@array/numberOptions"
android:entryValues="@array/numberValues"
android:key="number"
android:title="Number" />
Add
android:dependency="checkboxPref"
To the ListPreference XML
Result:
<ListPreference
android:entries="@array/numberOptions"
android:entryValues="@array/numberValues"
android:key="number"
android:title="Number"
android:dependency="checkboxPref"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With