【发布时间】:2015-12-09 08:31:46
【问题描述】:
您好,当用户第一次打开对话框时,我正在尝试在日期选择器对话框上设置特定日期(来自服务器)。之后,日期将动态设置。但我无法在日期选择器上获得该日期。它始终显示当前的最小日期。有什么简单的方法可以解决这个问题吗?
//My date from server
Calendar cal = Calendar.getInstance();
long l = Long.parseLong(posttime);
cal.setTimeInMillis(l);
int dmonth = cal.get(Calendar.DAY_OF_MONTH);
int dday = cal.get(Calendar.MONTH);
int dyear= cal.get(Calendar.YEAR);
dateTextView.setText(dday+" " + dmonth + " " +dyear);
//Date to be set dynamically
Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
PostInfoUpdate.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)+1
);
dpd.setMinDate(Calendar.getInstance());
now.add(Calendar.DAY_OF_MONTH, 30);
dpd.setMaxDate(now);
//To open the dialog
public void show() {
dpd.show(getFragmentManager(), "Datepickerdialog");
}
//To set the date
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
String date = "You picked the following date: "+dayOfMonth+"/"+(++monthOfYear)+"/"+year;
dateTextView.setText(date);
}
【问题讨论】:
标签: android date datepicker