On my view I have a button which when pressed pops up a DatePickerDialog. The poppedup dialog has a \"Done\" button. When I press that button the selected date is populated
Instead of implementing custom DatePickerDialog, you can implement custom OnClickListener for positive button:
DatePickerDialog dateDialog = new DatePickerDialog(this, null, year, month, day);
datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE,
getResources().getString(R.string.text_done),
new OnDoneClickListener(datePickerDialog));
// <...>
private class OnDoneClickListener implements DialogInterface.OnClickListener {
private DatePickerDialog mPickerDialog;
BirthDatePickerDialog(DatePickerDialog mPickerDialog) {
this.mPickerDialog = mPickerDialog;
}
@Override
public void onClick(DialogInterface dialog, int which) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
DatePicker picker = mPickerDialog.getDatePicker();
cal.set(Calendar.YEAR, picker.getYear());
cal.set(Calendar.MONTH, picker.getMonth());
cal.set(Calendar.DAY_OF_MONTH, picker.getDayOfMonth());
spinnerDateBirth.setText(dateFormat.format(cal.getTime()));
}
}
Any of back or tap on empty area will dismiss the dialog with doing nothing.