Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preferences being enabled dependent on other Preference

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.

like image 806
Boardy Avatar asked Sep 13 '12 21:09

Boardy


People also ask

How do I turn off preferences on Android?

Programmatically: getPreferenceScreen(). findPreference("yourpref"). setEnabled(false);

What are preferences Android?

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)

What is the difference of SharedPreference to preference?

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.

Which of these methods can be used to view the user preferences in the context of overall Android framework?

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.


1 Answers

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)

like image 174
Kevin Coppock Avatar answered Oct 18 '22 19:10

Kevin Coppock