title: Prevent user from selecting past time - TimePickerDialog
body: <h2><strong>IMPORTANT EDIT:</strong> I've done a bit of searching and it seems that the OnTimeChangedListener doesn't fire in Android 5.0 (API 21). Gustavo's answer below will work for API 20 or lower, and API 22 which I've tested. (<a href="https://code.google.com/p/android/issues/detail?id=78861/" rel="nofollow" title="Source">Source</a>)</h2>
  
  <p>I would like to prevent a user from entering a time prior to the current time. I check for a valid time using the <code>before</code> method provided by <code>Date</code>. How can I prevent the dialog from accepting an invalid time within this validity check? </p>
  
  <p>I have omitted excess code where I initialize the selected time (as a <code>Date</code>).</p>
  
  <pre><code>final Calendar mcurrentTime = Calendar.getInstance();
  final int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
  final int minute = mcurrentTime.get(Calendar.MINUTE);
  final TimePickerDialog mTimePicker;
  mTimePicker = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
      @Override
      public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
  
          //PSEUDO: Date selectedDateTime init here
  
          if (selectedDateTime.before(mcurrentTime.getTime())) {
              // prevent user from selecting time
          }
      }
  }, hour, minute, true);//true = 24 hour time
  mTimePicker.setTitle("Select Time");
  mTimePicker.show(); 
  </code></pre>