开发者

PreferenceActivity validating user input and showing error messages

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开发者_StackOverflow screen, since it seems like disappearing right before the OnPreferenceChangeListener callback gets executed.

Any ideas?


Well, there isn't an event for you to use BEFORE the user has finished has edit, as written in android dev:

The interface has only one callback method, onSharedPreferenceChanged()

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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜