Android : Subclass RelativeLayout with secondary constructors in Kotlin

on Sunday, September 21, 2014


I'm tryin to subclass RelativeLayout in Kotlin but I'm stuck with the three constructors.



public RelativeLayout(Context context) {}
public RelativeLayout(Context context, AttributeSet attrs) {}
public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {}


I've tried the process described in http://devnet.jetbrains.com/message/5482057 but I don't see how I can match those to my use case.


Hoping that the three constructors called each other, I've tried to use default values but it crashes at app startup:



class SquareRelativeLayout(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
: RelativeLayout(context, attrs!!, defStyle) {}


Any hint on the idiomatic Kotlin way to do this?


0 comments:

Post a Comment