Android:检查生成的首选项
我
public class Preferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
想在保留偏好之前进行健全性检查。我可以在 onAcitivtyResult() 方法期间调用首选项活动的活动中执行此操作。但这意味着如果我必须告诉用户更正首选项,我必须再次调用我想避免的首选项活动。在我离开此偏好活动之前,是否可以通过某种方式进行检查?只有当健全性检查正常时,用户才能离开首选项活动。我想我必须覆盖后退按钮,是吗?
谢谢。
I have
public class Preferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
Before the preferences are left I want to do a sanity check. I can do that in activity which calls the preference activity during the onAcitivtyResult()
method. But that means if I have to tell the user to correct the preferences I have to call the preference activity again which I want to avoid. Is there some way that I can do a check before I leave this preference activity? Something that the user can only leave the preference activity when the sanity check is ok. I guess I have to override the back button, do I?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 http://developer.android.com/reference/android/首选项/Preference.OnPreferenceChangeListener.html 在设置某个首选项时立即收到通知。从那里,你可以做出相应的反应。
You could use http://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener.html to get notified right when a certain preference has been set. From there, you could react accordingly.