위의 블로그에서 사용된
@SuppressLint("PrivateApi")
fun setInterval(
@IntRange(from = 1, to = 30)
timeInterval: Int = defaultInterval
) {
try {
val classForId = Class.forName("com.android.internal.R\$id")
val fieldId = classForId.getField("minute").getInt(null)
(this.findViewById(fieldId) as NumberPicker).apply {
minValue = DateTimeUtil.MINUTES_MIN
maxValue = DateTimeUtil.MINUTES_MAX / timeInterval - 1
displayedValues = getDisplayedValue()
}
} catch (e: Exception) {
e.printStackTrace()
}
}
해당 코드에서
try문 부분을 이와 같이 수정한다.
try {
(this.findViewById(
Resources.getSystem().getIdentifier(
"minute",
"id",
"android"
)) as NumberPicker).apply {
minValue = resources.getInteger(R.integer.minutes_min)
maxValue = resources.getInteger(R.integer.minutes_max) / timeInterval - 1
displayedValues = getDisplayedValue()
}