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?
The preference option doesn't exist anymore. You will need to right click the res -> new -> Android resource file and choose the resource type as xml in the dropdown. Then you will manually need to add the layout for preference xml.
PreferencesActivity is a way to easily create preference screens such as those in Android itself, just look under Settings . These can be used inside applications to easily save preferences to SharedPreferences and then easily access these from within your app. See this page for more information on PreferenceActivity.
Programmatically: getPreferenceScreen(). findPreference("yourpref"). setEnabled(false);
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:
<CheckBoxPreference android:title="Pref1" android:key="pref1"> </CheckBoxPreference>
Here's the code(preference xml layout) to put in for pref2:
<EditTextPreference android:dialogMessage="Pref 2 dialog" android:title="Pref2" android:key="pref2" android:dependency="pref1"> </EditTextPreference>
Like sigmazero13 said, by default disableDependentsState is false so you don't need to include it in the pref1 attributes.
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