Hello,
I’m trying to create a custom GridView in my Android project and I’ve run into an issue with secondary constructors.
In Java it would look like the following:
public class MyGridViewJava extends GridView {
public MyGridViewJava(Context context) {
super(context);
}
public MyGridViewJava(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridViewJava(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
If I convert to Kotlin we get:
public class MyGridViewJava : GridView() {
public constructor(context: Context) : super(context) {
}
public constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
}
public constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
}
}
This has an error:
So we can modify the Kotlin class to fix that:
public class MyGridViewJava(context: Context) : GridView(context: Context) {
public constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
}
public constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
}
}
But now this has an issue with the secondary constructor:
What am I missing for this inheritance to work correctly?
Cheers,