TimePicker SetHour Method
android
Solution
I'm not sure if there is already a support library for this, but this is what I've done when I was dealing with these methods:
Java:
private void setTime(int hour, int minute) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mTimePicker.setHour(hour);
mTimePicker.setMinute(minute);
} else {
mTimePicker.setCurrentHour(hour);
mTimePicker.setCurrentMinute(minute);
}
}
And in Kotlin:
private fun setTime(hours: Int, minutes: Int) {
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
time_picker.hour = hours
time_picker.minute = minutes
} else {
time_picker.currentHour = hours
time_picker.currentMinute = minutes
}
}
Problem
I obtain a warning in Android Studio upon using the setCurrentHour Method (as below), that it has been deprecated. ``` timePicker.setCurrentHour(hour); ``` Meanwhile, upon using the setHour Method (as hereafter), I obtain a warning stating that the "Call requires API level 23" while the current minimum is lower. ``` timePicker.setHour(hour); ``` Is there a Support Library that I could use for Backward Compatibility, avoiding thus any warnings?