码迷,mamicode.com
首页 > 其他好文 > 详细

======DatePickerDialog时间选的符合标准才消失======

时间:2015-02-03 11:15:58      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:android

		mDateDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定",
				new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						resetDialog(mDateDialog, true);
						Field field;
						try {
							field = dialog.getClass().getDeclaredField(
									"mCalendar");
							field.setAccessible(true);
							Calendar c = (Calendar) field.get(dialog);
							calendar.set(Calendar.YEAR, c.get(Calendar.YEAR));
							calendar.set(Calendar.MONTH, c.get(Calendar.MONTH));
							calendar.set(Calendar.DAY_OF_MONTH,
									c.get(Calendar.DAY_OF_MONTH));
							calendar.set(Calendar.HOUR, 0);
							calendar.set(Calendar.MINUTE, 0);
							calendar.set(Calendar.SECOND, 0);
							calendar.set(Calendar.MILLISECOND, 0);

							Calendar currentCalendar = Calendar
									.getInstance(Locale.CHINA);
							currentCalendar.set(Calendar.HOUR, 0);
							currentCalendar.set(Calendar.MINUTE, 0);
							currentCalendar.set(Calendar.SECOND, 0);
							currentCalendar.set(Calendar.MILLISECOND, 0);
							if (currentCalendar.before(calendar)
									|| currentCalendar.equals(calendar)) {

								String str = calendar.get(Calendar.YEAR) + "年"
										+ (calendar.get(Calendar.MONTH) + 1)
										+ "月"
										+ calendar.get(Calendar.DAY_OF_MONTH)
										+ "日";
								text_value_product_deli_time.setText(str);

							} else {

								resetDialog(mDateDialog, false);
								ToastUtils.t(mContext, "您不能穿越");

							}
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
						} catch (IllegalArgumentException e) {
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						}

					}
				});

======DatePickerDialog时间选的符合标准才消失======

标签:android

原文地址:http://blog.csdn.net/soulofandroid/article/details/43445705

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!