title: Is there a way to use cancel in Android JellyBean TimePickerDialog?
body: <p>As far as I am aware, versions prior to Jelly Beans, had <kbd>Set</kbd> and <kbd>Cancel</kbd> buttons when using <strong>TimePickerDialog</strong>. Jelly Beans has only <kbd>Done</kbd> button.</p>
  
  <p>I could just leave the <kbd>Done</kbd> button, and could close the dialog by clicking outside the dialog, but my <code>onTimeSetListener</code> gets called if pressing <kbd>Done</kbd> or outside the dialog.</p>
  
  <p>So I found <a href="https://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel">this stackoverflow question</a> which describes, that there is a bug when using <strong>DatePickerDialog</strong>. To fix the issue using <strong>DatePickerDialog</strong>, when initializing I had to set the <code>onDateSetListener</code> to <code>null</code>, and implement my own buttons to handle the <code>BUTTON_POSITIVE</code> (Set) and <code>BUTTON_NEGATIVE</code> (Cancel) onClick method. Which is fine, because when button <kbd>Set</kbd>  is called I can access the <strong>DatePicker</strong> values like this</p>
  
  <pre><code>int yearPicked = dateDlg.getDatePicker().getYear();
  int monthPicked = dateDlg.getDatePicker().getMonth();
  int dayPicked = dateDlg.getDatePicker().getDayOfMonth();
  </code></pre>
  
  <p>So there is no need to use <code>onDateSetListener</code>, but if I would, it would again be called when pressing Set or Cancel.</p>
  
  <p>I tried to use <strong>TimePickerDialog</strong> the same way, but the problem is, that inside <code>BUTTON_POSITIVE</code> onClick method, I cannot access the hour and minutes values as before, because <strong>TimePickerDialog</strong> does not provide <strong>TimePicker</strong> as <strong>DatePickerDialog</strong> provides <strong>DatePicker</strong>. And again if I would used <code>onTimeSetListener</code>, it would be called by pressing anything.</p>
  
  <pre><code>Calendar cal = Calendar.getInstance();
  
  int hour = cal.get(Calendar.HOUR_OF_DAY);
  int min = cal.get(Calendar.MINUTE);
  
  final TimePickerDialog timeDlg = new TimePickerDialog(PreferencesActivity.this, null, hour, min, true);
  
  // Make the Set button
  timeDlg.setButton(DialogInterface.BUTTON_POSITIVE, "Set", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
          if (which == DialogInterface.BUTTON_POSITIVE) {
              // CANNOT ACCES THE VALUES
              Toast.makeText(PreferencesActivity.this, "Set", Toast.LENGTH_SHORT).show();
          }
      }
  });
  
  
  // Set the Cancel button
  timeDlg.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
          if (which == DialogInterface.BUTTON_NEGATIVE) {
              Toast.makeText(PreferencesActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
          }
      }
  });
  
  timeDlg.show();
  </code></pre>