SeekBarPreference 似乎没有保留其值
我在 XML 文件中有一个 SeekBarPreference
可以显示(并且滑块可以工作),但是在单击 OK
按钮后,该值似乎消失了。
这是我的 XML 文件...
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SeekBarPreference android:key="NOTE_MINIMUM"
android:summary="Set the lowest note in the playback sound"
android:max="125"
android:title="Lowest note"
android:persistent="true"
android:defaultValue="25" />
<CheckBoxPreference android:key="COLOR_CODING"
android:title="Show playback progress bar"
android:summary="string/color_coding_summary"
android:defaultValue="true" />
</PreferenceScreen>
我可以获取代码中的 COLOR_CODING
字段的值,但不能获取 NOTE_MINIMUM
字段,该字段使用 < code>prefs.getInt("NOTE_MINIMUM", -11);
但我认为问题出在首选项对话框中。当我选中 COLOR_CODING
框并关闭然后打开 PreferencesScreen
时,它的状态仍然存在。当我移动 NOTE_MINIMUM
对话框上的滑块(并单击 OK
)时,关闭重新打开应用程序会显示滑块,就像应用程序初始化时一样,并带有滑块位于其轨道的开头。
谁能帮我解决这个问题。
I have a SeekBarPreference
in an XML file which displays (and the slider works), but after I click the OK
button, the value just seems to disappear.
This is my XML file...
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SeekBarPreference android:key="NOTE_MINIMUM"
android:summary="Set the lowest note in the playback sound"
android:max="125"
android:title="Lowest note"
android:persistent="true"
android:defaultValue="25" />
<CheckBoxPreference android:key="COLOR_CODING"
android:title="Show playback progress bar"
android:summary="string/color_coding_summary"
android:defaultValue="true" />
</PreferenceScreen>
I can get the value of the COLOR_CODING
field in my code, but not the NOTE_MINIMUM
field, which comes back as an unknown field using prefs.getInt("NOTE_MINIMUM", -11);
But I think the problem is in the preferences dialog. When I check the COLOR_CODING
box and close then open the PreferencesScreen
, it's state persists. When I move the slider on the NOTE_MINIMUM
dialog (and click OK
), doing a close-reopen of the app shows the slider as it was when the app initialised, with the slider at beginning of its track.
Could anyone please help me with this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答了。
最后,我创建(剪切并粘贴某人的)
SeekBarPreference
代码并将其放入我的应用程序中的一个类中,amd 称之为该类而不是 api 类。然而,这与其说是一个答案,不如说是一个解决方法。
我仍然不明白为什么 android
SeekBarPreference
但它不以与 androidCheckBoxPreference
相同的方式存储其结果(不需要额外的应用程序代码侦听器捕获它的状态)。我仍然有兴趣看到另一个答案,因为您自己的代码似乎是其他人使用的方法。
Answered.
In the end I created (cut and pasted someone's)
SeekBarPreference
code and made it into a class in my app amd called that rather than the api class.However, this is not so much an answer as a workaround.
I still don't understand why the android
SeekBarPreference
but it doesn't store its result in the same way that the androidCheckBoxPreference
does (with no additional app code listener needed to capture it's state).I'd still be interested to see another answer as this roll your own code seems to be the method everyone else uses.