Skip to content

Instantly share code, notes, and snippets.

@SCOTT-HAMILTON
Created June 19, 2021 13:31
Show Gist options
  • Save SCOTT-HAMILTON/e5abcd072d084fdaf965b78cd0177057 to your computer and use it in GitHub Desktop.
Save SCOTT-HAMILTON/e5abcd072d084fdaf965b78cd0177057 to your computer and use it in GitHub Desktop.
// Credits go to https://stackoverflow.com/a/61340341
package com.sample.piview
import android.content.Context
import android.util.AttributeSet
import androidx.preference.DialogPreference
class NumberPickerPreference(context: Context?, attrs: AttributeSet?) :
DialogPreference(context, attrs) {
override fun getSummary(): CharSequence {
return getPersistedInt(INITIAL_VALUE).toString()
}
fun getPersistedInt() = super.getPersistedInt(INITIAL_VALUE)
fun doPersistInt(value: Int) {
super.persistInt(value)
notifyChanged()
}
companion object {
// allowed range
const val INITIAL_VALUE = 80
const val MIN_VALUE = 0
const val MAX_VALUE = 100_000
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment