Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you tried following the <a href="http://developer.android.com/resources/tutorials/views/hello-timepicker.html" rel="nofollow">tutorial on the developers page</a> for the timepicker?</p> <p><strong>Edit:</strong></p> <p>Ok, so following the tutorial we have the update method for the textview that will show your time: </p> <pre><code>private void updateDisplay() { mTimeDisplay.setText( new StringBuilder() .append(pad(mHour)).append(":") .append(pad(mMinute))); } private static String pad(int c) { if (c &gt;= 10) return String.valueOf(c); else return "0" + String.valueOf(c); } </code></pre> <p>The dialog that will be created for the user to pick the time:</p> <pre><code>@Override protected Dialog onCreateDialog(int id) { switch (id) { case TIME_DIALOG_ID: return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, false); } return null; } </code></pre> <p>And here is where I would add the restriction that you want, the callback method when the user sets the time. You need to get the current hour and minute, and if the user selects a past time, you do not display his changes and send him a Toast or something.</p> <p>Using the Calendar you can easily get it:</p> <pre><code>Calendar c = Calendar.getInstance(); // the callback received when the user "sets" the time in the dialog private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { if (mHour &gt;= Integer.getInteger(c.get(Calendar.HOUR_OF_DAY)) &amp;&amp; mMinute &gt;= Integer.getInteger(c.get(Calendar.MINUTE))) { mHour = hourOfDay; mMinute = minute; updateDisplay(); } else //Display a toast or something to inform the user that he can't pick a past time. } </code></pre> <p>Now if you want the user to not be able to pick a previous time in the Dialog you created, you have to create your own hour picking screen, because the TimePickerDialog has no restrictions about what values you can pick. </p> <p>Hope it helps!</p>
 

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