我每次打开时都会使用滚轮瞄准器对话框显示当前日期而不是我之前设置的日期。
我无法找到应该在哪里进行更改。谢谢。
这是代码:
public static void showDatePickerDialog(final context ctx, 最终的TextView视图,最终的EditText preMobileNumberText){
final Handler mHandler = new Handler();
final Calendar dateandtime = Calendar.getInstance(Locale.US);
final DateFormat format = new SimpleDateFormat("MMM dd yyyy", Locale.US);
DatePickerDailog dp = new DatePickerDailog(ctx, dateandtime,
new DatePickerDailog.DatePickerListner() {
@Override
public void OnDoneButton(Dialog datedialog, Calendar c) {
dateandtime.set(Calendar.YEAR, c.get(Calendar.YEAR));
dateandtime.set(Calendar.MONTH, c.get(Calendar.MONTH));
dateandtime.set(Calendar.DAY_OF_MONTH,c.get(Calendar.DAY_OF_MONTH));
String selectedDate = new SimpleDateFormat(
"MMMM dd yyyy").format(c.getTime());
Date date = null;
Date cdate = null;
try {
date = format.parse(selectedDate);
long selectedmilliseconds = date.getTime();
cdate = format.parse(getCurrentDate());
long currentmilliseconds = cdate.getTime();
if ((selectedmilliseconds - currentmilliseconds) > 0) {
AlertDialogClass
.showAlertNFC(
ctx,
"Please do not select the Future Date for Date of Birth",
"Info");
} else {
datedialog.dismiss();
view.setText(selectedDate);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
preMobileNumberText.requestFocus();
preMobileNumberText.requestFocusFromTouch();
}
@Override
public void OnCancelButton(Dialog datedialog) {
// TODO Auto-generated method stub
datedialog.dismiss();
// preMobileNumberText.requestFocus();
}
});
dp.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dp.show();
}
答案 0 :(得分:1)
尝试以下代码:
Calendar cal=Calendar.getInstance();
cal.set(Calendar.YEAR, YOUR YEAR VALUE);
cal.set(Calendar.MONTH, YOUR MONTH VALUE);
cal.set(Calendar.DAY_OF_MONTH, YOUR DAY VALUE);
dateandtime.set(Calendar.YEAR, c.get(Calendar.YEAR));
dateandtime.set(Calendar.MONTH, c.get(Calendar.MONTH));
dateandtime.set(Calendar.DAY_OF_MONTH,c.get(Calendar.DAY_OF_MONTH));
答案 1 :(得分:0)
只需将变量设置为您想要的日期即可。多数民众赞成:)
DatePickerDialog对话框=新的DatePickerDialog(this,datePickerListener,年,月,日);
dialog.show();