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()
}
我只想选择从上午10点到下午2点的时间,然后在时间选择器对话框中选择下午4点到晚上8点。 我添加了代码,但是如何在时间选择中设置范围 我在其中放了最小范围和最大范围