如果我在首选项中选择任何其他控件,SeekBar 值会自动在首选项中重置
我已经通过java代码将SeekBar控件添加到首选项中。它已添加并显示在首选项中。我还在首选项中添加了 EditTextPreference 和复选框。现在我将搜索栏拖动到某个值。在此之后,如果我选择复选框,则搜索栏将重置为初始值(我的意思是说所选搜索栏值不会保留......它会返回......)。 请您指导我出了什么问题吗?
I have added a SeekBar control to the preference by java code. It's got added and shown up in the preference. I also added a EditTextPreference and a checkbox to the preference. Now I dragged up the seekbar to some value. After this if I select checkbox the seekbar gets reset to initial value ( I meant to say the selected seekbar value not staying ...it is going back...).
Do you please guide me what went wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可能需要做的是实现 OnSeekBarChanged 并将 onProgressChanged 函数添加到您的代码中,然后将其将搜索栏首选项重置为当前值。由于您没有包含任何代码,也没有指定,我不知道您是否尝试过重置该值。如果您没有这样做,则搜索栏会将自身设置回首选项值是有道理的。希望能有所帮助。
What I think you may need to do is implement OnSeekBarChanged and add an onProgressChanged function to your code, then have it reset the seekbar preference to the current value. Since you didn't include any code, nor did you specify, I don't know if you ever tried to reset the value. If you didn't, it makes sense that the seekbar would set itself back to the preference value. Hope that helps a bit.
我发现问题出在哪里了。实际上,每当编辑 checkboxpreference 或 edittextpreference 时,都会调用自定义首选项的 OnCreateView 方法。我只是从自定义首选项的 onCreateView 方法中保存的共享首选项中重置 SeekBar 值。这解决了我的问题。感谢大家的回复。
I found where the problem is. Actually OnCreateView method of the custom preference gets called whenever the checkboxpreference or edittextpreference been edited. I am just resetting the SeekBar value from sharedpreferences saved values in onCreateView method of my custom preference. That fixed my problem. And thanks to all for there replies.