@BindingAdapter(
"onTimeViewClick",
"onLocationViewClick",
"onSetDeliveryAddressClick",
)
internal fun setSubHeaderData(
onTimeViewClick: (() -> Unit)?,
onLocationViewClick: (() -> Unit)?,
onSetDeliveryAddressClick: (() -> Unit)?,
) {
view.onTimeViewClick = onTimeViewClick
view.onLocationViewClick = onLocationViewClick
view.onSetDeliveryAddressClick = onSetDeliveryAddressClick
}
Code when called from xml
<ModeSelectorSubHeaderView
android:id="@+id/mode_selector_sub_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
app:onLocationViewClick="@{ () -> mainViewModel.onSetDeliveryAddressTest(mainViewModel.viewState.headerInfo) }"
app:onSetDeliveryAddressClick="@{ mainViewModel::onSetDeliveryAddressClick }"
/>
The above code works. But when I change the method called in
app:onSetDeliveryAddressClick="@{ () -> mainViewModel.onSetDeliveryAddressClick(mainViewModel.viewState.headerInfo) }"
it gives missing return statement error in generated code.
The code is very much identical to the call app:onLocationViewClick
The error:
/XXXX/databinding/ActivityMainBindingImpl.java:849: error: missing return statement } ^ 1 error
Binding adapter itself can only be used with interface or abstract classes with one abstract method.
The documentation does not officially mention that it supports kotlin lambda.
You can check this documentation.
So Replacing kotlin lambda with the interface with one abstract method may be solve your problem.