获取android中选择的偏好值
有没有办法获取列表首选项新选择的值。我尝试使用 onClick 和 onChange 方法获取值,但它们都返回以前的值。据我所知,内部状态是在调用此方法后设置的。有什么方法可以获取列表首选项的当前选定值,以便我可以将该值传递给绑定服务来重新安排计时器。请帮助我...
这是我使用的代码:
Preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub Context c = getApplicationContext(); SharedPreferences sp = preference.getSharedPreferences(); String period = sp.getString("prefKey", "defValue"); return true; } });
Is there any way to get the newly selected value for a list preference. I have tried to get the values using onClick and onChange methods, but both of them returning the previous value. I understand that the internal state is set after calling this method. Is there any way to get the current selected value for a list preference so that I can pass the value to a binded service to reschedule a timer. Please help me ...
Here s the code I used:
Preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub Context c = getApplicationContext(); SharedPreferences sp = preference.getSharedPreferences(); String period = sp.getString("prefKey", "defValue"); return true; } });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过重新检查方法后,我终于得到了自己的答案。
侦听器方法中有一个名为“newValue”的对象。顾名思义,它是选择的新值:)
Finally I have got the answer my self after rechecking the method.
There is an object called 'newValue' in the listener method. As the name says, its the new value selected :)