I can inject dependencies in activities and fragments, but can I inject in custom view?
class AppInputView : SearchView {
private val router: Krouter by inject() // Unresolved reference: inject
init {
this.onQuerySubmit {
context.toast(it)
this.onActionViewCollapsed()
this.clearFocus()
}
}
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
}
You can add the KoinComponent interface to your component, to unlock by inject() properties.
Yes. It works. Thank you for great product!
can you please give an example on how to inject Service into a Custom View class ?
if my CustomView class extends FrameLayout, how can i use the KoinComponent interface?
Thanks a head
can you please give an example on how to inject Service into a Custom View class ?
if my CustomView class extends FrameLayout, how can i use the KoinComponent interface?
Thanks a head
Maybe this:
class MyCustomView(context: Context) : FrameLayout(context), KoinComponent {
...
}
Most helpful comment
You can add the
KoinComponentinterface to your component, to unlockby inject()properties.