Last active
February 28, 2017 14:04
-
-
Save danielgomezrico/e51337945d9277e6c5ad95e1abe33daf to your computer and use it in GitHub Desktop.
Android / Kotlin - Using @jvmoverloads tag to avoid multiple "empty" constructors for inheritance (shown with custom android views). (thanks to https://discuss.kotlinlang.org/t/simple-constructors-for-inheritance/1874/2)
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 MyCustomView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0) | |
: FrameLayout(context, attrs, defStyleAttr){ | |
init { | |
// ... | |
} | |
} |
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 MyCustomView : FrameLayout { | |
constructor(context: Context) : super(context) { | |
init() | |
} | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | |
init() | |
} | |
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) | |
: super(context, attrs, defStyleAttr) { | |
init() | |
} | |
fun init() { | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment