Sure.
textField.addFocusListener(new FocusListener() {
public void focusGained(Component cmp) {}
public void focusLost(final Component cmp) {
// check if input is valid, e.g. is shorter than 5 chars, if not then
if (!(((TextField) cmp).getText().length() < 5)) {
// show dialog to the user
Dialog.show("Error", "Max length is 4 chars!", Dialog.TYPE_ERROR, null, "Ok", null);
// return focus to this component
cmp.requestFocus();
// this was added as Shai suggested
Display.getInstance().callSerially(new Runnable() {
public void run() {
Display.getInstance().editString(cmp, ((TextField) cmp).getMaxSize(), ((TextField) cmp).getConstraint(), ((TextField) cmp).getText());
}
});
}
}
});
If non-valid text entered, do not let user out of textField (either by pressing "next" on VK, or by touching outside of textfield). Simple as that.