I wrote a custom BindingAdapter for when the close icon on a Chip is being clicked:
@BindingAdapter("onCloseClicked")
fun Chip.onCloseClicked(onCloseClicked: () -> Unit) {
setOnCloseIconClickListener { onCloseClicked() }
}
I bind it in my layout like this:
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="com.example.playground.MyViewModel" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chip 1"
app:closeIconEnabled="true"
app:onCloseClicked="@{() -> viewModel.chip1CloseClicked()}" />
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chip 2"
app:closeIconEnabled="true" />
</LinearLayout>
</layout>
When I only bind 1 chip (like above), all works fine. When I also bind the 2nd chip like:
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chip 2"
app:closeIconEnabled="true"
app:onCloseClicked="@{() -> viewModel.chip2CloseClicked()}" />
the app doesn't build anymore due to a databinding error:
com/example/playground/databinding/ActivityMainBindingImpl.java
error: missing return statement
Any ideas on why this occurs and how to fix it?