1
fun openTimePicker(){
    mHour = c.get(Calendar.HOUR_OF_DAY)
    mMinute = c.get(Calendar.MINUTE)
    c.setTime(c.getTime());
    // Launch Time Picker Dialog
    val timePickerDialog = TimePickerDialog(this,
            TimePickerDialog.OnTimeSetListener {
                view, hourOfDay, minute ->
                hour = hourOfDay
                minutes = minute
                var timeSet = ""
                if (hour > 12) {
                    hour -= 12
                    timeSet = "PM"
                } else if (hour === 0) {
                    hour += 12
                    timeSet = "AM"
                } else if (hour === 12) {
                    timeSet = "PM"
                } else {
                    timeSet = "AM"
                }
                if (minutes < 10)
                    min = "0$minutes"
                else
                    min = minutes.toString()
                val date = StringBuilder()
                date.append(hour).append(':')
                        .append(min ).append(" ").append(timeSet).toString()
                Toast.makeText(this,date,Toast.LENGTH_LONG).show()
               // txtTime.setText(hourOfDay.toString() + ":" + minute)
            },
            mHour, mMinute, false)

    timePickerDialog.show()
}

I want to select a time from 10 am to 2 pm only and then select 4 pm to 8 pm in the time picker dialog. I added code but how to set range in time selection where I put minimum range and maximum range in it

Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • You have to create custom class for this, check this link- https://stackoverflow.com/questions/20214547/show-timepicker-with-minutes-intervals-in-android – Rashpal Singh Oct 01 '18 at 09:44

0 Answers0