Inheriting from GridView / Secondary Constructers


#1

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:
/uploads/kotlinlang/original/1X/f81eb172466909798708588a98d1abbef84c8a3a.png

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:
/uploads/kotlinlang/original/1X/7bbce0e93c80c6527b22a3ce57f935e98cfb44d7.png

What am I missing for this inheritance to work correctly?

Cheers,


#2

Converter didn't do it correctly, remove parentheses from ": GridView()"


#3

Yikes, thanks.

Would you like me to create a issue for this?
Seems like it may trip others up in the future.

Thanks again,


#4

The issue has been fixed and the fix will be available soon. Thanks for your report.