Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Change button text in DatePickerDialog / TimePickerDialog
    primarykey
    data
    text
    <p>I have got a DatePickerDialog. In the default configuration it works fine.</p> <pre><code>DatePickerDialog dialog = new DatePickerDialog( view.getContext(), new OnDateSetListener() { @Override public void onDateSet(DatePicker picker, int year, int monthOfYear, int dayOfMonth) { // do something } }, startDate.getYear(), startDate.getMonth() - 1, startDate.getDay() ); </code></pre> <p><img src="https://i.stack.imgur.com/Sx4s5.png" alt="enter image description here"></p> <p>Now I want to change the text of the buttons. I try it with the following code:</p> <pre><code>dialog.setButton(DatePickerDialog.BUTTON_POSITIVE, "New Label", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do something } }); </code></pre> <p>Now my problem is to get the date from the datepicker control. The DateSetListener will not be called by click on the button. How is it possible to get the date via the DateSetListener? Another possibility to get the date is about</p> <pre><code>public void onClick(DialogInterface dialog, int which) { int year = ((DatePickerDialog) dialog).getDatePicker().getYear(); int month = ((DatePickerDialog) dialog).getDatePicker().getMonth(); int day = ((DatePickerDialog) dialog).getDatePicker().getDayOfMonth(); } </code></pre> <p>But this seems to be a unnecessary complicated way.</p> <p>For the TimePickerDialog this alternative way will not work because I find no way to get the timepicker control. Therefore I need to use the TimeSetListener but I cannot find the possibility (like for the datepicker).</p> <p>Thanks for any response.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload