在首选项活动中将复选框设置为 false
我正在尝试实现用户偏好。我遇到的一个问题是,如果我的一个复选框被勾选,我想将另一个设置为 false。我了解依赖性,并且据我所知,它不会改变价值。只是禁止您更改首选项。如果另一个复选框为 true,我该如何将其更改为 false?这是我的 xml:
<PreferenceCategory android:title="Launch Settings">
<CheckBoxPreference
android:key="enable_nearest_station"
android:title="Nearest station"
android:defaultValue="false"
android:summary="Will launch your nearest station on startup"
android:disableDependentsState="true"/>
<CheckBoxPreference
android:key="enable_default_station"
android:title="Default station"
android:defaultValue="false"
android:dependency="enable_nearest_station"
android:summary="Allows you to choose a default to launch with."
/>
/>
</PreferenceCategory>
提前致谢。
I am trying to implement user preferences. A problem I have is that if one of my check boxes is ticked I want to set the other to false. I know about dependency and from what I have seen it doesn't change the value. Just disables you from changing the preference. What can I do to change a checkbox to false if another is true? This is my xml:
<PreferenceCategory android:title="Launch Settings">
<CheckBoxPreference
android:key="enable_nearest_station"
android:title="Nearest station"
android:defaultValue="false"
android:summary="Will launch your nearest station on startup"
android:disableDependentsState="true"/>
<CheckBoxPreference
android:key="enable_default_station"
android:title="Default station"
android:defaultValue="false"
android:dependency="enable_nearest_station"
android:summary="Allows you to choose a default to launch with."
/>
/>
</PreferenceCategory>
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 set
setOnPreferenceChangeListener(Preference.OnPreferenceChangeListener onPreferenceChangeListener)
到您的 CheckBoxPreference 并使用代码将其他 CheckBoxPreference 设置为 false。Use the set
setOnPreferenceChangeListener(Preference.OnPreferenceChangeListener onPreferenceChangeListener)
to your CheckBoxPreference and code to set false other CheckBoxPreference.