国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2019-12-12 01:43:11
字體:
供稿:網(wǎng)友

抽出來了一個方法來選擇時間(這里自己規(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í)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 纳雍县| 全州县| 福州市| 靖边县| 兴城市| 达拉特旗| 邢台县| 涟源市| 卓尼县| 尚志市| 神木县| 平远县| 博兴县| 海城市| 工布江达县| 彰化县| 延安市| 珲春市| 台南县| 宾阳县| 汾阳市| 广昌县| 拉孜县| 科尔| 达孜县| 靖边县| 泾川县| 临猗县| 奇台县| 隆昌县| 咸阳市| 富蕴县| 石家庄市| 洪湖市| 灌阳县| 邮箱| 综艺| 海口市| 隆回县| 甘洛县| 莎车县|