Skip to content

Instantly share code, notes, and snippets.

@amyu
Created November 27, 2016 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyu/30ec80b98ef0ddaa27e6089745a8e06d to your computer and use it in GitHub Desktop.
Save amyu/30ec80b98ef0ddaa27e6089745a8e06d to your computer and use it in GitHub Desktop.
class DatabindingableNumberPicker : NumberPicker {
constructor(context: Context) : super(context)
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr)
private var isCallSetMaxValueBeforeSetValue = false
private var tempValue = 0
override fun setValue(value: Int) {
if (!isCallSetMaxValueBeforeSetValue) {
tempValue = value
isCallSetMaxValueBeforeSetValue = true
} else {
super.setValue(value)
}
}
override fun setMaxValue(maxValue: Int) {
super.setMaxValue(maxValue)
if (isCallSetMaxValueBeforeSetValue) {
value = tempValue
} else {
isCallSetMaxValueBeforeSetValue = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment