PreferenceActivity 验证用户输入并显示错误消息
我正在使用 PreferenceActivity 供用户定义应用程序的某些设置。
我还使用 OnPreferenceChangeListener 接口来获取首选项更改的通知,在该回调中,我可以验证用户的输入,并且可以在拒绝用户输入时做出更新决策。
当我检测到验证错误时,我希望在屏幕上保持首选项编辑对话框处于活动状态,以便我可以使用 .getTextEdit().setError() 方法设置错误消息以通知用户。但是,我无法设法使对话框在屏幕上保持活动状态,因为它似乎在 OnPreferenceChangeListener 回调执行之前消失了。
有什么想法吗?
I am using a PreferenceActivity for user to define certain settings for the application.
I am also using the OnPreferenceChangeListener interface to get notifications of changed preferences, and within that callback, I can do validation of the user's input, and I can make decisions on updating on rejecting user's input.
When I detect a validation error, I would like to keep the preference editing dialog box active on the screen, so that I can use the .getTextEdit().setError() method to set an error message to inform the user. However, I wasn't able to manage to keep the dialog box active on the screen, since it seems like disappearing right before the OnPreferenceChangeListener callback gets executed.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,在用户完成编辑之前,没有一个事件可供您使用,如 android dev 中所写:
我要做的是实现一个自定义首选项,
(如 http://developer.android.com/guide/topics 中所述/ui/settings.html#自定义)
但我不会扩展 DialogPreference,而是扩展 EditTextPreference。
虽然还没有测试过,但听起来应该可行。祝你好运 :)
Well, there isn't an event for you to use BEFORE the user has finished has edit, as written in android dev:
What I would do is implement a custom preference,
(as explained in http://developer.android.com/guide/topics/ui/settings.html#Custom)
But instead of extending DialogPreference i would extend EditTextPreference.
Haven't tested it though, but sounds like it should work. Good luck :)