我的应用程序中需要一个日期选择器对话框。首先,我打开日期选择器对话框并选择日期。下次打开日期选择器对话框时,日期选择器的日期应该是设备的当前日期。但是,它会在对话框中显示最后选择的日期。请帮我设置代码。这是我现在拥有的代码:
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case DATE_DIALOG_ID:
Date d=new Date();
Calendar c=Calendar.getInstance();
c.setTimeZone(tz);
c.setTime(d);
d=c.getTime();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
DatePickerDialog datePicker
= new DatePickerDialog(this, datePickerListener, year, month, date);
return datePicker;
}
return super.onCreateDialog(id);
}
private DatePickerDialog.OnDateSetListener datePickerListener
= new DatePickerDialog.OnDateSetListener()
{
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay)
{
cors_year = selectedYear;
cors_month = selectedMonth;
cors_date = selectedDay;
getDate("calledfromDialog");
displaySunTime();
displayChoghadiya("Day");
displayTime(3, 1);
dayButtonClicked();
selected_DAY_NIGHT="Day";
}
};