Created
November 27, 2016 10:46
-
-
Save amyu/30ec80b98ef0ddaa27e6089745a8e06d 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
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