Android中的日期和时间选择器
2016-11-17 18:26
211 查看
抽出来了一个方法来选择时间(这里自己规定的只能选择当前时间以后的日期),日期选择完毕就会自动弹出时间选择器让选择时间
/** * 选择日期和时间 */ private void selectDataAndTime() { // 获取当前时间 final Calendar calendar = Calendar.getInstance(); /* * toast("当前时间是:" + 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); }
相关文章推荐
- Android:设置日期和时间不能选择当前时刻以前的日期时间的解决办法
- Android日期选择组件与时间选择组…
- 时间与日期选择器——Mars Android开发视频之第一季第十六集(重)
- Android之日期及时间选择对话框
- android时间日期选择器,监听
- Android:设置日期和时间不能选择当前时刻以前的日期时间的解决办法
- Android日期时间选择控件使用详解
- Android之日期及时间选择对话框用法实例分析
- android 时间和日期选择器 监听设置时间按钮
- android自定义日期和时间选择对话框得实现
- android 时间选择器和日期选择器,sdk上说可以实现自动同步,貌似不行
- Android UI控件系列:DatePicker,TimePicker(日期和时间选择)
- Android表单组件,单选,多选,下拉列表,日期选择,时间选择
- Android应用程序用户界面(十一)时间日期选择对话框
- 19. android dialog —— 日期和时间选择对话框
- Android开发之日期时间选择组件事…
- Android开发之日期、时间选择器(DatePicker和TimePicker)的功能和用法
- android应用开发详解(九)------------------日期和时间选择对话框
- Android中弹窗选择日期,时间,并将选择结果保存 TimePickerDialog DatePickerDialog
- Android之日期时间选择器使用方法