最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android日期和時間選擇器實(shí)現(xiàn)代碼

 更新時間:2017年11月10日 10:18:10   作者:Glydi  
這篇文章主要為大家詳細(xì)介紹了Android日期和時間選擇器實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

抽出來了一個方法來選擇時間(這里自己規(guī)定的只能選擇當(dāng)前時間以后的日期),日期選擇完畢就會自動彈出時間選擇器讓選擇時間。

  /**
   * 選擇日期和時間
   */
  private void selectDataAndTime() {
    // 獲取當(dāng)前時間
    final Calendar calendar = Calendar.getInstance();
    /*
     * toast("當(dāng)前時間是:" + calendar.get(Calendar.YEAR) + "," +
     * calendar.get(Calendar.MONTH) + "," +
     * calendar.get(Calendar.DAY_OF_MONTH));
     */
    // 日期選擇對話框
    dataPickerDialog = new DatePickerDialog(this, new OnDateSetListener() {

      @Override
      public void onDateSet(DatePicker view, int year, int month, int day) {
        // 判斷用戶選擇的日期是否合法
        if (calendar.get(Calendar.YEAR) > year) {
          toast("時間有誤,請從新選擇");
          return;
        } else if (calendar.get(Calendar.YEAR) == year) {
          if (calendar.get(Calendar.MONTH) > month) {
            toast("時間有誤,請從新選擇");
            return;
          } else if (calendar.get(Calendar.MONTH) == month) {
            if (calendar.get(Calendar.DAY_OF_MONTH) > day) {
              toast("時間有誤,請從新選擇");
              return;
            } else {
              strDate = year + "-" + (month + 1) + "-" + day;
              if (timePickerDialog != null) {
                timePickerDialog.show();
              }
            }
          } else {
            strDate = year + "-" + (month + 1) + "-" + day;
            if (timePickerDialog != null) {
              timePickerDialog.show();
            }
          }
        } else {
          strDate = year + "-" + (month + 1) + "-" + day;
          if (timePickerDialog != null) {
            timePickerDialog.show();
          }
        }
      }
    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar
        .get(Calendar.DAY_OF_MONTH));
    // 時間選擇對話框
    timePickerDialog = new TimePickerDialog(this, new OnTimeSetListener() {

      @Override
      public void onTimeSet(TimePicker view, int hour, int minute) {
        strTime = strDate + " " + hour + ":" + minute;
        timeTt.setText(strTime);
      }
    }, calendar.get(Calendar.HOUR), calendar.get(Calendar.MINUTE), true);
  }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

蛟河市| 榆林市| 来宾市| 穆棱市| 宁陵县| 濮阳县| 巫溪县| 峨边| 陆河县| 中超| 朔州市| 铁岭县| 广昌县| 哈尔滨市| 凉城县| 黄骅市| 玉门市| 监利县| 城口县| 娄底市| 洪泽县| 大宁县| 班玛县| 策勒县| 庆阳市| 亳州市| 彰化县| 从化市| 河东区| 隆回县| 图片| 栾川县| 临沂市| 望谟县| 滦平县| 伊川县| 青神县| 澳门| 惠东县| 扎兰屯市| 会宁县|