7

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?

Cinar
  • 183
  • 1
  • 1
  • 11
  • I don't think this can be done, because the preference does not change until the user clicks OK, and by that time the box is already closed, that is when the listener is called. But hey, if someone has some ideas or if it can be, I'm interested too. – Thomas Dignan Jun 21 '11 at 17:26

1 Answers1

1

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

Sean
  • 5,176
  • 2
  • 34
  • 50