I am having trouble with a DatePickerDialog
, everytime I open it shows the current date not the date I set previously.
Here's my code:
final Calendar c = Calendar.getInstance();
final int mYear = c.get(Calendar.YEAR);
final int mMonth = c.get(Calendar.MONTH);
final int mDay = c.get(Calendar.DAY_OF_MONTH);
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) {
editText.setText(selectedYear + "年"
+ selectedMonth + 1 + "月"
+ selectedDay + "日");
}
};
DatePickerDialog datePickerDialog = new DatePickerDialog(SampleActivity.this,
datePickerListener, mYear, mMonth, mDay);
datePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
dialog.cancel();
}
}
});
datePickerDialog.setCancelable(false);
datePickerDialog.show();
What did I miss here?