I want my program to store credentials for a remote service, so the user would set them in preferences once and never do that again.
So I’ve subclassed a DialogPreference, and my class displays a nice dialog with two fields for login and password. Very good.
Now I want to validate the data when the user entered it and clicked OK, just to prevent the stupid situation when bad login is stored and we have to peek the user with warnings and ask him to go and enter the data again.
Here is the first problem: the default behaviour of the DialogPreference is closing when the button is clicked (I wonder why?)—of course I can override onDialogClosed() and validate the login there, but the dialog is closed no matter if I call super.onDialogClosed() or not.
OK, after a couple of hours searching and trying I’ve found an answer that looks great at the first glance: the click handler on the positive button allows what I want. But another problem comes: as the original click handler is replaced, the dialog doesn’t close anymore. Calling super.onDialogClosed() doesn’t help; I assume that this method is just a notification that doesn’t provide any control.
So how to close the DialogPreference programmatically with positive result? Since I replace the default click handler for my positive button, I guess I need to call the old handler myself, but how to do that?
Did you tried calling
dismiss()method of the Dialog class after you done with the validation?like :
getDialog().dismiss()