Created
June 19, 2021 13:31
-
-
Save SCOTT-HAMILTON/e5abcd072d084fdaf965b78cd0177057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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