2016-05-09 88 views
1

我想在我的應用程序中顯示DateTime選擇器,所以我寫下面的代碼來顯示DateTime Picker,Date代碼中的代碼問題

Form dialogtimeForm  = new Form("Set time"); 
        dialogtimeForm.setUIID("workersListForm"); 
        if(!Constants.PLATFORMNAME.equals(Display.getInstance().getPlatformName())){ 
          spinner = new DateTimeSpinner(){ 
          @Override 
          protected Dimension calcPreferredSize() { 
           return new Dimension(460, 180); 
          } 
         }; 
        } else{ 
         spinner = new DateTimeSpinner(); 
        } 
        spinner.setShowMeridiem(true); 
        spinner.setMinuteStep(1); 
        int hours    = 0; 
        int minutes    = 0; 
        boolean showMeridiem = false; 
        Date date    = null; 
        timeValue    = data; 

        if(timeValue != null && !"".equals(timeValue)){ 
         hours    = Util.getHours(timeValue); 
         minutes    = Util.getMinutes(timeValue); 
         showMeridiem  = Util.getAmPm(timeValue); 
         date    = Util.getDate(DBActuallCallDate); 
        } 
        if(hours > 12){ 
         hours    = hours -12; 
         showMeridiem  = true; 
        } 

        spinner.setCurrentHour(hours); 
        spinner.setCurrentMinute(minutes); 
        spinner.setCurrentMeridiem(showMeridiem); 
        spinner.setCurrentDate(date); 

        dialogtimeForm.add(spinner); 
        Dialog dialog    = new Dialog(); 
        dialog.setDisposeWhenPointerOutOfBounds(true); 

        commands[0]     = new Command(Constants.SETCOMMAND){ 
         @Override 
         public void actionPerformed(ActionEvent evt) { 
          int hour   = spinner.getCurrentHour(); 
          int minute   = spinner.getCurrentMinute(); 
          boolean meridiem = spinner.isCurrentMeridiem(); 
          String time   = Util.timeConversion(hour, minute, meridiem); 
          String workerTime = Util.getFormatedTimeValue(time, spinner.getCurrentDate()); 
          callInField.setText(time); 
          roasterDao = new RoasterDao(); 
          if(flag.equals(Constants.ACTUALCALLOUTFLAG)) 
           roasterDao.updateActualCallOutTime(workerTime, serialId); 
          else 
           roasterDao.updateActualCallInTime(workerTime, serialId); 

          dialog.dispose(); 
          if(ApplicationScopeBean.dialogShow){ 
           if(flag.equals(Constants.ACTUALCALLOUTFLAG)) 
            Dialog.show("Alert", workerName+Constants.CHECKOUTSUCCESSFULLY+time,"ok",null); 
           else 
            Dialog.show("Alert", workerName+Constants.CHECKINSUCCESSFULLY+time,"ok",null); 
          } else{ 
           if(flag.equals(Constants.ACTUALCALLOUTFLAG)) 
            Toast.makeText(RoasterApp.getContext(), workerName+Constants.CHECKOUTSUCCESSFULLY+time, Toast.LENGTH_LONG).show(); 
           else 
            Toast.makeText(RoasterApp.getContext(), workerName+Constants.CHECKINSUCCESSFULLY+time, Toast.LENGTH_LONG).show(); 
          } 
          Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable(); 
          unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable"); 
          unScheduledWorkerBoxContainer.removeAll(); 
          unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer); 
          unScheduledWorkersForm.revalidate(); 
         } 
        }; 
        commands[1] = new Command(Constants.CLEARCOMMAND){ 
         @Override 
         public void actionPerformed(ActionEvent evt) { 
          Dialog dialog1 = new Dialog(); 
          dialog1.setUIID("listDialog"); 
          String clearCallOutDialog = Constants.CLEARCALLOUTDIALOG; 
          String clearCallInDialog = Constants.CLEARCALLINDIALOG; 
          dialog.dispose(); 
          FlowLayout centerLayout  = new FlowLayout(); 
          centerLayout.setAlign(Component.CENTER); 
          centerLayout.setValign(Component.TOP); 
          Container flowContainer  = new Container(centerLayout); 
          Container boxXAxisLayout = new Container(new BoxLayout(BoxLayout.X_AXIS)); 
          Button okButton = new Button(Constants.OKCOMMAND); 
          okButton.setUIID("dialogCloseButton"); 
          okButton.addActionListener(new ActionListener() { 
           @Override 
           public void actionPerformed(ActionEvent evt) { 
            roasterDao   = new RoasterDao(); 
            if(flag.equals(Constants.ACTUALCALLOUTFLAG)) 
             roasterDao.updateActualCallOutTime("", serialId); 
            else 
             roasterDao.updateActualCallInTime("", serialId); 
            callInField.setText(""); 
            dialog1.dispose(); 
            dialog.dispose(); 
            Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable(); 
            unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable"); 
            unScheduledWorkerBoxContainer.removeAll(); 
            unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer); 
            unScheduledWorkersForm.revalidate(); 
           } 
          }); 
          Button close     = new Button(Constants.CANCELCOMMAND); 
          close.setUIID("dialogCloseButton"); 
          close.addActionListener(new ActionListener() { 
           @Override 
           public void actionPerformed(ActionEvent evt) { 
            dialog1.dispose(); 
            dialog.dispose(); 
            Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable(); 
            unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable"); 
            unScheduledWorkerBoxContainer.removeAll(); 
            unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer); 
            unScheduledWorkersForm.revalidate(); 
           } 
          }); 

          boxXAxisLayout.add(okButton); 
          boxXAxisLayout.add(close); 
          flowContainer.add(boxXAxisLayout); 

          dialog1.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE)); 
          String dataLabelString = ""; 
          if(flag.equals(Constants.ACTUALCALLOUTFLAG)) 
           dataLabelString  = clearCallOutDialog; 
          else 
           dataLabelString  = clearCallInDialog; 
          Label dataLabel   = new Label(dataLabelString); 
          dataLabel.setUIID("confirmDialogBody"); 
          dialog1.add(BorderLayout.CENTER, dataLabel); 
          dialog1.add(BorderLayout.SOUTH, flowContainer); 
          dialog1.show(); 
         } 
        }; 
        commands[2] = new Command(Constants.CANCELCOMMAND){ 
         @Override 
         public void actionPerformed(ActionEvent evt) { 
          dialog.dispose(); 
          Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable(); 
          unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable"); 
          unScheduledWorkerBoxContainer.removeAll(); 
          [![enter image description here][1]][1]unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer); 
          unScheduledWorkersForm.revalidate(); 
         } 
        }; 
        dialog.show("", dialogtimeForm, commands); 

請找到截圖。 enter image description here

enter image description here

回答

1

Picker API將顯示在支持的平臺本機的日期/時間UI。日期,時間,數字和字符串在Android上受支持,但DateTime僅在iOS上受支持,因此您會看到「後備」UI。您可能需要