In the following code, the Validator of the PickerComponent "date" is never executed on the Simulator with "GooglePixel2.skin", instead is executed with "iPhoneX.skin". Why? In the log there isn't the string "Validator of date executed" after picking a date on Android (in the simulator), instead that string is continuosly logged on iPhone (in the simulator). Is my code incorrect?
I tried to follow this example: https://www.codenameone.com/javadoc/com/codename1/ui/layouts/TextModeLayout.html
public void show(Form backForm) {
TextModeLayout textModeLayout = new TextModeLayout(4, 1);
Container inputPersonData = new Container(textModeLayout);
TextComponent name = new TextComponent().label("Nome");
TextComponent surname = new TextComponent().label("Cognome");
PickerComponent gender = PickerComponent.createStrings("Maschio", "Femmina", "altro");
PickerComponent date = PickerComponent.createDate(new Date());
Validator val = new Validator();
val.addConstraint(name, new LengthConstraint(2));
val.addConstraint(surname, new LengthConstraint(2));
val.addConstraint(date, new Constraint() {
@Override
public boolean isValid(Object value) {
Log.p("Validator of date executed");
boolean res = false;
if (value instanceof Date) {
Calendar birthday = Calendar.getInstance();
birthday.setTime((Date) value);
Calendar nowLess13years = Calendar.getInstance();
nowLess13years.setTime(new Date());
nowLess13years.add(Calendar.YEAR, -13);
if (birthday.before(nowLess13years) || birthday.equals(nowLess13years)) {
res = true;
}
}
return res;
}
@Override
public String getDefaultFailMessage() {
return "You must be at least 13 years old";
}
});
inputPersonData.add(name);
inputPersonData.add(surname);
inputPersonData.add(gender);
inputPersonData.add(date);
add(inputPersonData);
super.show();
Log.p("Registry Form shown correctly");
}