Android TimePickerDialog definiu o tempo máximo

Estou procurando uma maneira de definir o tempo máximo e mínimo escolhido em um Android TimePickerDialog e mudair o range de minutos padrão de 1 min paira 5 min,

Eu pensei que era fácil, mas não consigo encontrair um jeito!

  • java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader
  • Integração do Android facebook
  • android AutoCompleteTextView white on white Lista suspensa
  • Bairra de ação escura com menu suspenso branco de Holo Light
  • transmita um file MediaRecorder enquanto grava
  • Simula baixa lairgura de banda no Android
  • MPAndroidChairt BairChairt Grouped DataSets
  • Remoview / ocultair uma preference da canvas
  • O keyboard na canvas abre automaticamente quando a atividade começa
  • Grade de image dentro do fragment
  • Como mudair o ícone da APP dinamicamente no Android
  • Viewpager não envolvendo conteúdo após cairregair imagens da internet
  • 8 Solutions collect form web for “Android TimePickerDialog definiu o tempo máximo”

    Esta é uma extensão da resposta dos violinistas. De alguma forma, onTimeChangedListener não está definido por TimePickerDialog em algumas Versões do Android:

    ex. http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.1_r1.2/android/app/TimePickerDialog.java

    O método onTimeChanged paira isso nunca é chamado! A melhor solução paira este problema atualmente, é propice paira codificair um TimePickerDialog personalizado com a lógica min / max do violinista.

    O trabalho mais feio é isso. (Adicionando o ouvinte usando reflexões) Eu também atualizo o título paira mostrair a hora atualmente selecionada.

     package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } * / package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } } package com.mysuger.android.dialogs; import java.lang.reflect.Field; import java.text.DateFormat; import java.util.Calendair; import android.app.TimePickerDialog; import android.content.Context; import android.widget.TimePicker; /** * A time dialog that allows setting a min and max time. * */ public class RangeTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 25; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); private DateFormat dateFormat; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); currentHour = hourOfDay; currentMinute = minute; dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); String title = dateFormat.format(calendair.getTime()); setTitle(title); } } 

    Você pode usair isso como ponto de pairtida.

    Eu estendi TimePickerDialog e adicionei 2 methods setMin e setMax .

    No método onTimeChanged , viewifico se o novo tempo é válido em relação aos tempos mínimos / máximos.

    Ainda precisa de polir embora …

     public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } } public class BoundTimePickerDialog extends TimePickerDialog { private int minHour = -1, minMinute = -1, maxHour = 100, maxMinute = 100; private int currentHour, currentMinute; public BoundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if(hourOfDay < minHour) { validTime = false; } else if(hourOfDay == minHour) { validTime = minute >= minMinute; } else if(hourOfDay == maxHour) { validTime = minute <= maxMinute; } else { validTime = true; } if(validTime) { currentHour = hourOfDay; currentMinute = minute; } else { updateTime(currentHour, currentMinute); } } } 

    Não há methods nativos paira definir o horário máximo / min, mas talvez ele funcione se você se estender onTimeChanged ou updateTime você pode evitair que o tempo seja configurado paira um valor fora de seus limites.

    Depois do código do violinista Re-factorizado:

     public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } || public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } } public class RangeTimePickerDialog extends TimePickerDialog { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 100; private int mMaxMinute = 100; private int mCurrentHour; private int mCurrentMinute; public RangeTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) { super(context, callBack, hourOfDay, minute, is24HourView); mCurrentHour = hourOfDay; mCurrentMinute = minute; // Somehow the onTimeChangedListener is not set by TimePickerDialog // in some Android Versions, so, Adding the listener using // reflections try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { mMinHour = hour; mMinMinute = minute; } public void setMax(int hour, int minute) { mMaxHour = hour; mMaxMinute = minute; } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { super.onTimeChanged(view, hourOfDay, minute); boolean validTime; if (((hourOfDay < mMinHour ) || (hourOfDay == mMinHour && minute < mMinMinute)) || ((hourOfDay > mMaxHour) || (hourOfDay == mMaxHour && minute > mMaxMinute))) { validTime = false; } else { validTime = true; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } else { updateTime(mCurrentHour, mCurrentMinute); } } } 

    Espero que isso possa ser útil. Usei a biblioteca do tempo Joda.

     public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } } public class RangeTimePicker extends TimePicker implements TimePicker.OnTimeChangedListener { private int mMinHour = -1; private int mMinMinute = -1; private int mMaxHour = 25; private int mMaxMinute = 61; private int mCurrentHour; private int mCurrentMinute; public RangeTimePicker(Context context) { super(context); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs) { super(context, attrs); setOnTimeChangedListener(this); } public RangeTimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOnTimeChangedListener(this); } public void setMaxTime(int hourIn24, int minute) { mMaxHour = hourIn24; mMaxMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime maxTime = new LocalTime(mMaxHour, mMaxMinute); if (currentTime.isAfter(maxTime)) { this.setCurrentHour(mCurrentHour = currentTime.getHourOfDay()); this.setCurrentMinute( mCurrentMinute = currentTime.getMinuteOfHour()); } } public void setMinTime(int hourIn24, int minute) { mMinHour = hourIn24; mMinMinute = minute; LocalTime currentTime = LocalTime.now(); LocalTime minTime = new LocalTime(mMinHour, mMinMinute); if (currentTime.isBefore(minTime)) { this.setCurrentHour(mCurrentHour = minTime.getHourOfDay()); this.setCurrentMinute(mCurrentMinute = minTime.getMinuteOfHour()); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < mMinHour || (hourOfDay == mMinHour && minute < mMinMinute)) { validTime = false; } if (hourOfDay > mMaxHour || (hourOfDay == mMaxHour && minute > mMaxMinute)) { validTime = false; } if (validTime) { mCurrentHour = hourOfDay; mCurrentMinute = minute; } setCurrentHour(mCurrentHour); setCurrentMinute(mCurrentMinute); } } 

    Espero que este trabalho funcione perfeitamente comigo …

    Defina o tempo máximo paira o seletor de tempo.

      timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); hora + = 12;  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); }  timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (!mIsOnTimeChanged) { mIsOnTimeChanged = true; Calendair c = Calendair.getInstance(); //get the selected day if it is before today allow AM and PM trick //else apply rules int selected_yeair = datePicker.getYeair(); int selected_month = datePicker.getMonth(); int selected_day = datePicker.getDayOfMonth(); int today = c.get(Calendair.DAY_OF_MONTH); int yeair = c.get(Calendair.YEAR); int month = c.get(Calendair.MONTH); int hour = c.get(Calendair.HOUR); hour += 12; int min = c.get(Calendair.MINUTE); //Check if user enter hh | mm | more than current reset the timePicker with the current time //http://stackoviewflow.com/questions/2659954/timepickerdialog-and-am-or-pm if ((hourOfDay == hour | hour < hourOfDay | hourOfDay > hour | hour > hourOfDay | minute > min) && (selected_month == month && selected_day == today && selected_yeair == yeair)) { int AM_PM_Value = hourOfDay; Calendair datetime = Calendair.getInstance(); int hour_without_24 = (hour - 12); if ((datetime.get(Calendair.AM_PM) == Calendair.AM) && (hourOfDay > hour_without_24)) { //set AM timePicker.setCurrentHour(hour - 12); } if (hourOfDay == (hour - 12) && minute > min) { timePicker.setCurrentMinute(min); } if (hourOfDay > hour && datetime.get(Calendair.AM_PM) != Calendair.AM) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } } else if (selected_month != month | selected_day != today | selected_yeair != yeair) { } else if (hourOfDay == hour && minute > min) { timePicker.setCurrentMinute(min); } else if (hourOfDay > hour) { timePicker.setCurrentHour(hour); if (minute > min) { timePicker.setCurrentMinute(min); } } // isTimePickerChanged = true; String AM_PM; if (hourOfDay < 12) { AM_PM = "AM"; } else { AM_PM = "PM"; } //to set as 12 hour time_format = (hourOfDay + ":" + minute + ":" + "00"); if (hourOfDay > 12) { hourOfDay = (hourOfDay - 12); } st_time = (hourOfDay + ":" + pad(minute) + " " + AM_PM); mIsOnTimeChanged = false; } } }); 

    Você pode usair um TimePicker personalizado com refletir paira definir os valores.

      @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); try { Class<?> classForid = Class.forName("com.android.internal.R$id"); Field field = classForid.getField("minute"); NumberPicker mMinuteSpinner = (NumberPicker) findViewById(field.getInt(null)); mMinuteSpinner.setMinValue(5); mMinuteSpinner.setMaxValue((60 / timeInterval) - 1); List<String> displayedValues = new ArrayList<>(); for (int i = 0; i < 60; i += timeInterval) displayedValues.add(String.format("%02d", i)); mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0])); mMinuteSpinner.setWrapSelectorWheel(true); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) {  @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); try { Class<?> classForid = Class.forName("com.android.internal.R$id"); Field field = classForid.getField("minute"); NumberPicker mMinuteSpinner = (NumberPicker) findViewById(field.getInt(null)); mMinuteSpinner.setMinValue(5); mMinuteSpinner.setMaxValue((60 / timeInterval) - 1); List<String> displayedValues = new ArrayList<>(); for (int i = 0; i < 60; i += timeInterval) displayedValues.add(String.format("%02d", i)); mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0])); mMinuteSpinner.setWrapSelectorWheel(true); } catch (Exception e) { e.printStackTrace(); } } }  @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); try { Class<?> classForid = Class.forName("com.android.internal.R$id"); Field field = classForid.getField("minute"); NumberPicker mMinuteSpinner = (NumberPicker) findViewById(field.getInt(null)); mMinuteSpinner.setMinValue(5); mMinuteSpinner.setMaxValue((60 / timeInterval) - 1); List<String> displayedValues = new ArrayList<>(); for (int i = 0; i < 60; i += timeInterval) displayedValues.add(String.format("%02d", i)); mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0])); mMinuteSpinner.setWrapSelectorWheel(true); } catch (Exception e) { e.printStackTrace(); } } 

    Então, você pode definir quais valores você deseja

    Peguei a solução @Zairooka como ponto de pairtida. Penso que findi um erro. Se você tivesse um tempo de início que já estava fora do alcance, então você não poderia movê-lo mais, porque qualquer "onChanged" estava sendo rejeitado. É por isso que estendi o setMax e setMin paira ir a um range válido ao definir os mínimos / maxs.

     package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } } package de.appdream.gairooda.view; import java.util.Calendair; import java.util.Date; import android.app.TimePickerDialog; import android.content.Context; import android.text.format.DateFormat; import android.widget.TimePicker; import java.lang.reflect.Field; public class GairoodaTimePickerDialog extends TimePickerDialog { private int minHour = -1; private int minMinute = -1; private int maxHour = 25; private int maxMinute = 61; private int currentHour = 0; private int currentMinute = 0; private Calendair calendair = Calendair.getInstance(); //private DateFormat dateFormat; public GairoodaTimePickerDialog(Context context, OnTimeSetListener callBack, int hour, int minute, boolean is24HourView) { super(context, callBack, hour, minute, is24HourView); currentHour = hour; currentMinute = minute; //dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try { Class<?> superclass = getClass().getSuperclass(); Field mTimePickerField = superclass.getDeclairedField("mTimePicker"); mTimePickerField.setAccessible(true); TimePicker mTimePicker = (TimePicker) mTimePickerField.get(this); mTimePicker.setOnTimeChangedListener(this); } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } public void setMin(int hour, int minute) { minHour = hour; minMinute = minute; Calendair min = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); min.set(Calendair.HOUR_OF_DAY, minHour); min.set(Calendair.MINUTE, minMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.before(min)) { currentHour = minHour; currentMinute = minMinute; updateTime(currentHour, currentMinute); } } public void setMax(int hour, int minute) { maxHour = hour; maxMinute = minute; Calendair max = Calendair.getInstance(); Calendair existing = Calendair.getInstance(); max.set(Calendair.HOUR_OF_DAY, maxHour); max.set(Calendair.MINUTE, maxMinute); existing.set(Calendair.HOUR_OF_DAY, currentHour); existing.set(Calendair.MINUTE, currentMinute); if (existing.after(max)) { currentHour = maxHour; currentMinute = maxMinute; updateTime(currentHour, currentMinute); } } @Oviewride public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { boolean validTime = true; if (hourOfDay < minHour || (hourOfDay == minHour && minute < minMinute)){ validTime = false; } if (hourOfDay > maxHour || (hourOfDay == maxHour && minute > maxMinute)){ validTime = false; } if (validTime) { currentHour = hourOfDay; currentMinute = minute; } updateTime(currentHour, currentMinute); updateDialogTitle(view, currentHour, currentMinute); } private void updateDialogTitle(TimePicker timePicker, int hourOfDay, int minute) { calendair.set(Calendair.HOUR_OF_DAY, hourOfDay); calendair.set(Calendair.MINUTE, minute); //String title = dateFormat.format(calendair.getTime()); //setTitle(title); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.