Custom View constructor in Android 4.4 crashes on Kotlin, how to fix? -


i have custom view written in kotlin using jvmoverloads have default value.

class myview @jvmoverloads constructor(     context: context,     attrs: attributeset? = null,     defstyle: int = 0,     defstyleres: int = 0 ) : linearlayout(context, attrs, defstyle, defstyleres) 

all works fine in android 5.1 , above.

however crashes in 4.4, since constructor in 4.4 doesn't have defstyleres. how have supported in 5.1 , above have defstyleres not in 4.4, without need explicitly having 4 constructors defined did in java?

note: below works fine in 4.4, loose defstyleres.

class myview @jvmoverloads constructor(     context: context,     attrs: attributeset? = null,     defstyle: int = 0 ) : linearlayout(context, attrs, defstyle) 

best way have class way.

class myview : linearlayout {     @jvmoverloads constructor(context: context, attrs: attributeset? = null, defstyleattr: int = 0) : super(context, attrs, defstyleattr)     @targetapi(build.version_codes.lollipop) constructor(context: context, attrs: attributeset?, defstyleattr: int, defstyleres: int) : super(context, attrs, defstyleattr, defstyleres) } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -