this.mInitDateTime = initDateTime;
}
public interface OnDateTimePickDialogListener {
void onDateTimePickDialog(String mResultDate);
}
public void setOnDateTimePickDialogListener(OnDateTimePickDialogListener listener) {
this.mListener = listener;
}
public void initDate(DatePicker datePicker) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
mInitDate = dateFormat.parse(mInitDateTime);            // 直接调⽤()⽅法时间会出现错误
} catch (ParseException e) {
e.printStackTrace();
}
Calendar calendar = Instance();
calendar.setTime(mInitDate);        // 设置初始化⽇期为当前⽇期
datePicker.(Calendar.YEAR), (Calendar.MONTH),
<(Calendar.DAY_OF_MONTH), this);
Logger.e("initDate", (Calendar.YEAR) + "," + ((Calendar.MONTH) + 1) + "," + (Calendar.DAY_OF_MONTH));                    // 设置不可编辑
datePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
// 设置min⽇期为初始⽇期
long minDate = TimeInMillis();
datePicker.setMinDate(minDate);        // 设置max⽇期为7天后
calendar.add(Calendar.DAY_OF_YEAR, 7);
long maxDate = TimeInMillis();
datePicker.setMaxDate(maxDate);
}
public AlertDialog dateTimePicKerDialog() {
LinearLayout dateTimeLayout = (LinearLayout)
mDatePicker = (DatePicker) dateTimeLayout.findViewById(R.id.dp_datepicker);
initDate(mDatePicker);
AlertDialog alertDialog
= new AlertDialog.Builder(mActivity)
.setTitle("选择时间")
.setView(dateTimeLayout)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
mChooseDate = dateFormat.parse(mDateTime);
if (Time() > Time()) {
} else if (Time() - Time() > 7000 * 60 * 60 * 24) {
} else {
// TODO 返回选择的时间
mResultDate = Tag(R.id.date_picker_dialog).toString();
Logger.e("resultData", mResultDate);
if (mListener == null) return;
}
} catch (Exception e) {
alertdialog使用方法
e.printStackTrace();
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).show();
// 初始化后⾃动添加onDateChanged监听
onDateChanged(null, 0, 0, 0);
return alertDialog;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。