代号一个PickerComponent setStartDate和setEndDate的用法

时间:2018-12-02 11:35:14

标签: codenameone

我尝试了以下代码来设置PickerComponent的startDate和endDate:

CSS:

    Form f = new Form(new TextModeLayout(1, 1));
    int MINAGE = 13;

    Calendar minAge = Calendar.getInstance(); // it's not a singleton, https://stackoverflow.com/questions/6055112/why-can-i-have-only-one-instance-of-calendar-object
    minAge.setTime(new Date()); // current time
    int year = minAge.get(Calendar.YEAR) - MINAGE;
    minAge.set(Calendar.YEAR, year);
    Date endDate = minAge.getTime();

    Calendar maxAge = Calendar.getInstance();
    maxAge.setTime(new Date());
    maxAge.set(Calendar.YEAR, 1930);
    maxAge.set(Calendar.MONTH, 1);
    maxAge.set(Calendar.DAY_OF_MONTH, 1);
    Date startDate = maxAge.getTime();

    PickerComponent inputCmp = PickerComponent.createDate(endDate).label("Birthday");
    Log.p("startDate: " + startDate.toString());
    Log.p("endDate: " + endDate.toString());
    inputCmp.getPicker().setStartDate(startDate);
    inputCmp.getPicker().setEndDate(endDate);

    f.add(inputCmp);
    f.show();

MainClass:

[EDT] 0:0:0,293 - startDate: Sat Feb 01 12:30:58 CET 1930
[EDT] 0:0:0,307 - endDate: Fri Dec 02 12:30:58 CET 2005
[EDT] 0:0:2,227 - Exception: java.lang.ArrayIndexOutOfBoundsException - Index out of bounds
java.lang.ArrayIndexOutOfBoundsException: Index out of bounds
    at com.codename1.ui.spinner.SpinnerNode.setSelectedIndex(SpinnerNode.java:284)
    at com.codename1.ui.spinner.SpinnerNode.rebuildChildren(SpinnerNode.java:213)
    at com.codename1.ui.spinner.SpinnerNode.setListModel(SpinnerNode.java:227)
    at com.codename1.ui.spinner.Spinner3D.setModel(Spinner3D.java:207)
    at com.codename1.ui.spinner.DateSpinner3D.setEndYear(DateSpinner3D.java:340)
    at com.codename1.ui.spinner.DateSpinner3D.setDateRange(DateSpinner3D.java:216)
    at com.codename1.ui.spinner.Picker$1.createDatePicker3D(Picker.java:490)
    at com.codename1.ui.spinner.Picker$1.showInteractionDialog(Picker.java:605)
    at com.codename1.ui.spinner.Picker$1.actionPerformed(Picker.java:303)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
    at com.codename1.ui.Button.fireActionEvent(Button.java:570)
    at com.codename1.ui.Button.released(Button.java:604)
    at com.codename1.ui.Button.pointerReleased(Button.java:708)
    at com.codename1.ui.Form.pointerReleased(Form.java:3339)
    at com.codename1.ui.Component.pointerReleased(Component.java:4528)
    at com.codename1.ui.Display.handleEvent(Display.java:2079)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:1051)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:969)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

但是当我尝试在选择器中选择日期时,我得到了:

{{1}}

在模拟器中测试。

1 个答案:

答案 0 :(得分:1)

这是Picker中的错误,我过去曾要求用户对此提交问题,但似乎他没有。似乎picker的默认行为是将1970显示为最早的日期。这显然是有问题的,应该解决。