InflationInject throws error when a custom view is a kotlin class with @JvmOverloads marked constructor
See original GitHub issueI defined this custom class with standard @JvmOverloads annotations to it’s constructor:
class CustomView @InflationInject @JvmOverloads constructor(
@Inflated context: Context,
@Inflated attrs: AttributeSet? = null,
@Inflated defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr)
But when compiling the annotation processor throws this error:
/android/ui/custom_views/CustomView.java:11: error: Multiple @InflationInject-annotated constructors found.
What is the proper way to do this in Kotlin? I can’t find any samples, so creating an issue here. Any help is appreciated, thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Custom View constructor in Android 4.4 crashes on Kotlin ...
Best way is to have your class this way. class MyView : LinearLayout { @JvmOverloads constructor(context: Context, attrs: AttributeSet?
Read more >Misconception about Kotlin @JvmOverloads for Android View ...
The root cause is that @JvmOverloads is a trick from Kotlin compiler that generates overload constructors, instead of the override constructors.
Read more >@JvmOverloads for Android Views - zsmb.co
The @JvmOverloads annotation is a convenience feature in Kotlin for ... class CustomView : View { constructor(context: Context) ...
Read more >Do not always trust @JvmOverloads | by Mateusz Młodawski
So always in our custom class, we will call the three-param constructor from TextInputEditText. Step 2: Understanding View's constructors. Now ...
Read more >Android Custom View Tutorial - RayWenderlich.com
Create an Android Custom View in Kotlin and learn how to draw shapes on the canvas, make views responsive, create new XML attributes, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This article by Dan Lew cleared things up for me a bit regarding view constructors: https://blog.danlew.net/2016/07/19/a-deep-dive-into-android-view-constructors/. @JakeWharton I suppose we can close this issue. Thanks for the help.
,