I am working on DatePicker and TimePicker in android. I am getting start time and and time from server. I can set max date and min date programmatically using this link
I want to set min time (07:00 ) and max time (10:00) in timepicker and maintain an interval of 30 minutes. I tried using This Link
What i need is to set timepicket with min 07:00 and max time =10:00 and intervals 07:00,07:30, 08:00 etc.
Here is the code same `
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TimePicker pn = (TimePicker) findViewById(R.id.tp_powernap); pn.setCurrentHour(7); pn.setCurrentMinute(0); System.out.println("timepicker erstellt"); pn.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS); System.out.println("Tastatur geblockt"); pn.setOnTimeChangedListener(StartTimeChangedListener); System.out.println("starttimechangedlistener"); pn.setIs24HourView(false); } private TimePicker.OnTimeChangedListener StartTimeChangedListener = new TimePicker.OnTimeChangedListener() { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { updateDisplay(view, hourOfDay, minute); } }; private TimePicker.OnTimeChangedListener NullTimeChangedListener = new TimePicker.OnTimeChangedListener() { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { } }; private void updateDisplay(TimePicker timePicker, int hourOfDay, int minute) { int nextMinute = 0; timePicker.setOnTimeChangedListener(NullTimeChangedListener); if (minute >= 45 && minute <= 59) nextMinute = 45; else if (minute >= 30) nextMinute = 30; else if (minute >= 15) nextMinute = 15; else if (minute > 0) nextMinute = 0; else { nextMinute = 45; } if (minute - nextMinute == 1) { if (minute >= 45 && minute <= 59) nextMinute = 00; else if(minute >= 30) nextMinute = 45; else if(minute >= 15) nextMinute = 30; else if(minute > 0) nextMinute = 15; else { nextMinute = 15; } } timePicker.setCurrentMinute(nextMinute); timePicker.setOnTimeChangedListener(StartTimeChangedListener); }