【问题标题】:Codename One - Validator of PickerComponent代号一 - PickerComponent 的验证器
【发布时间】:2018-05-08 22:26:53
【问题描述】:

在以下代码中,PickerComponent“日期”的验证器从未在模拟器上使用“GooglePixel2.skin”执行,而是使用“iPhoneX.skin”执行。为什么? 在 Android 上(在模拟器中)选择日期后,日志中没有字符串“执行日期验证器”,而是在 iPhone 上(在模拟器中)连续记录该字符串。我的代码不正确吗?

我试着按照这个例子: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");

    }

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    这似乎是验证器代码和选择器组件中的错误。它仅在我编辑其中一个字段后才对我有用,而不管皮肤如何。我已修复此问题以在任何地方正确绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多