I am trying to implement the MVVM architecture in my android application. I'm using Kotlin for the same.
This is my binding adapter class:
class BindingAdapter {
companion object {
@JvmStatic @BindingAdapter("app:visibleGone") fun showHide(view: View, show: Boolean) {
view.visibility =
if (show)
View.VISIBLE
else
View.GONE
}
}
}
Here is my XML file:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="isLoading"
type="boolean"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
android:orientation="vertical">
<TextView
android:id="@+id/loading_rates"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:text="@string/loading_rates"
android:textAlignment="center"
app:visibleGone="@{isLoading}"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
android:orientation="vertical"
app:visibleGone="@{!isLoading}">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:text="@string/rate_list"
android:textAlignment="center"
android:textSize="@dimen/rate_text"
android:textStyle="bold"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rate_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="LinearLayoutManager"/>
</LinearLayout>
</LinearLayout>
</layout>
The error message says:
Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:visibleGone' with parameter type boolean on android.widget.TextView. file:/home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate_list.xml loc:23:35 - 23:43 ****\ data binding error ****
Line 23 resolves to the loading_rates TextView's line just above the app:visibleGone statement
I'm not able to understand that despite setting the BindingAdapter inside my Kotlin class, why am I not able to compile the code succesfully?
