I am trying to pass a listener from an action to a class (adapter).
In java (code from Action):
private void setListeners() {
adapterRecyclerView.setListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SomeCodehere....
}
});
}
(code from adapter)
public void setListener(View.OnClickListener listener) {
this.listener = listener;
}
He works.
Now I'm trying to ferry Kotlin. First I translate the action (translate the action to kotlin):
private fun setListeners() {
adapterRecyclerView!!.setListener { v ->
SomeCodehere....
}
}
At this point, it still works. With adapter code still in java and class code in kotlin. Now translate the adapter to kotlin:
fun setListener(listener: View.OnClickListener) {
this.listener = listener
}
Now it will not work. The action does not compile.
Error: cannot deduce the type for this parameter "v". View.OnClickListener required. found (???) Unit.
How do I throw here? Why pass a parameter from kotlin to java work, and from kotlin to kotlin, is this not so?
source
share