I am currently working on an droid app and was wondering if there is a way that a preference can be enabled or disabled based on the value of another preference.
For example, if I have checkbox_pref1 if this is enabled then option2/3/4 are enabled, if checkbox_pref1 is disabled option2/3/4 automatically become disabled or is this there an XML attribute that would accomplish this or is it something that I would need to code to achieve this effect.
Thanks for any help you can provide.
Programmatically: getPreferenceScreen(). findPreference("yourpref"). setEnabled(false);
Preferences in Android are used to keep track of application and user preferences. In any application, there are default preferences that can accessed through the PreferenceManager instance and its related method getDefaultSharedPreferences(Context)
SharedPreferences ? Looks like they are for similar things - you can put and get a value by a key in both of them, but Preferences looks like something more difficult and belongs more to the OS than to an app.
In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences.
You can do this with the dependency
attribute. In your Preference
XML, you would add the following line to your checkbox_pref2
, checkbox_pref3
, and checkbox_pref2
Preferences:
android:dependency="checkbox_pref1"
Useful Links:
Android Quick Preferences Tutorial
Android Preference Documentation (#dependency)
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