preferences被启用依赖于其他preference [英] Preferences being enabled dependant on other Preference
问题描述
我目前工作的一个机器人的应用程序,并想知道如果有一种方式,一个preference可以基于另一个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.
例如,如果我有checkbox_ preF1如果启用该选项,然后选项2四分之三被使能/,如果checkbox_ preF1禁用选项2/3/4自动被禁用,或者这是有一个XML属性这将做到这一点或者是它的东西,我需要code,以达到这种效果。
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.
推荐答案
您可以使用依赖
属性做到这一点。在你的 preference
XML,你将下面的行添加到您的 checkbox_ preF2
, checkbox_ preF3
和 checkbox_ preF2
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"
相关链接:
<一个href=\"http://developer.android.com/reference/android/$p$pference/$p$pference.html#attr_android%3adependency\">Android preference文档(#dependency)
这篇关于preferences被启用依赖于其他preference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!