当前位置: 代码迷 >> 综合 >> DatePickerDialog 在Android 6.0.1上面没有回调onDateSet
  详细解决方案

DatePickerDialog 在Android 6.0.1上面没有回调onDateSet

热度:93   发布时间:2023-12-16 14:28:38.0

DatePickerDialog 在Android 6.0.1上面没有回调onDateSet, 在4.4.4 上面是可以回调的


参考这篇文章:http://blog.csdn.net/yuanyuan_186/article/details/51122484

1: onDateSet 里面不用去执行任何东西

2: 在下面的确认的回调里面去执行:

datePicker.setButton(DialogInterface.BUTTON_POSITIVE, "确认", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {updateCalendar(datePicker.getDatePicker().getYear(), datePicker.getDatePicker().getMonth(), datePicker.getDatePicker().getDayOfMonth());}});


实例:

final DatePickerDialog datePicker = new DatePickerDialog(getActivity(), R.style.timepicker, new DatePickerDialog.OnDateSetListener() {@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {//Do nothing, Things can be done in datePicker.setButton(DialogInterface.BUTTON_POSITIVE,,)//在Android 6.0.1中不会回调这里,所以就吧需要执行的直接放在datePicker.setButton(DialogInterface.BUTTON_POSITIVE,,)里面}}, mEndCalendar.get(Calendar.YEAR), mEndCalendar.get(Calendar.MONTH), mEndCalendar.get(Calendar.DAY_OF_MONTH));datePicker.getDatePicker().setCalendarViewShown(false);datePicker.setCancelable(true);datePicker.getDatePicker().setMinDate(mStartCalendar.getTimeInMillis());datePicker.getDatePicker().setMaxDate(new Date().getTime());datePicker.setButton(DialogInterface.BUTTON_POSITIVE, "确认", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {updateCalendar(datePicker.getDatePicker().getYear(), datePicker.getDatePicker().getMonth(), datePicker.getDatePicker().getDayOfMonth());}});datePicker.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}});datePicker.show();datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(getResources().getDimension(R.dimen.sp28));datePicker.getButton(DialogInterface.BUTTON_NEGATIVE).setTextSize(getResources().getDimension(R.dimen.sp28));}private void updateCalendar(int year, int monthOfYear, int dayOfMonth) {mEndCalendar.set(Calendar.YEAR, year);mEndCalendar.set(Calendar.MONTH, monthOfYear);mEndCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);mEndTimeTextView.setText(mFormat.format(mEndCalendar.getTime()));mEndTime = mEndCalendar.getTime();//默认的点击确定以后就更新一下订单getMasterOrderList(false,null);}





  相关解决方案