Search code examples
androidandroid-dialogfragmentandroid-dialogandroid-datepicker

In datePickerDialog how to replace the cancel button by clear button?


In datePickerDialog how to replace the cancel button by a clear button ? and catch the event when we click on it ?

enter image description here


Solution

  • This should solve your requirement:

        DatePickerDialog datePickerDialog = new DatePickerDialog(
                this, null, 2000, 1, 1);
        datePickerDialog.setButton(android.content.DialogInterface.BUTTON_NEGATIVE,
                getString(R.string.your_text), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // todo on click
                    }
                });
        datePickerDialog.show();