Pablichjenkov
11/20/2019, 5:32 PMclass CustomLayout : RelativeLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
private var mGlucoseState = GlucoseState.NONE
...
override fun onCreateDrawableState(extraSpace: Int): IntArray {
val drawableState = super.onCreateDrawableState(extraSpace + 7)
when (mGlucoseState) { // Crashing because mGlucoseState is null
GlucoseState.LOW -> View.mergeDrawableStates(
drawableState,
STATE_GLUCOSE_LOW
)
GlucoseState.DANGER_LOW -> View.mergeDrawableStates(
drawableState,
STATE_GLUCOSE_WARN_LOW
)
...
else -> View.mergeDrawableStates(
drawableState,
STATE_GLUCOSE_NONE
)
}
return drawableState
}
...
}