I'd like to have a date picker dialog with a "Today" button. If I click on Today button, it should reset datepicker to current date, without closing the dialog.
I have the following code:
Calendar today = Calendar.getInstance();
DatePickerDialog datePickerDialog = new DatePickerDialog(context, R.style.MyDialogStyle, date, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH));
datePickerDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Today", (dialog, which) -> {
datePickerDialog.updateDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
});
datePickerDialog.show();
Expected behavior: set datepicker's date to current date without closing the dialog.
Actual behavior: dialog closes, date doesn't change.
I also tried with new DatePickerDialog(...), and
datePickerDialog.getDatePicker().init(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH), null);
but it still doesn't work, only closes the dialog. What am I missing here?
Is there a way to update datepicker's date programmatically without closing the dialog?