I'm trying to implement RecyclerView with GridLayoutManager and I'm stuck. I'm receiving error:
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
Open File"
When I'm trying to compile. "Open file" provides me to xml recycler view declaration.
This is my BindingAdapter:
@BindingAdapter("listData")
fun bindRecyclerView(recyclerView: RecyclerView,
data: List<MarsPropertyData>?) {
val adapter = recyclerView.adapter as PhotoGridAdapter
adapter.submitList(data)
}
How I'm calling the above:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/photos_grid"
android:clipToPadding="false"
app:layoutManager=
"androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:itemCount="16"
tools:listitem="@layout/grid_view_item"
app:listData="@{viewModel.properties}"
/>
And this is my properties variable:
val properties: LiveData<List<MarsPropertyData>>
I'm understand that IDE complains about data types, my properties
var it is LiveData<List<MarsPropertyData>>
and inside BindingAdapter
there's just normal List, but I saw example from google in which logic was made in same way and it worked fine.
Yes, I have added 'kotlin-kapt'
plugin, I have another BindingAdapter which works fine.
I experienced a similar problem while working on a google codelab whose setup is very similar to yours. In my case, I inadvertently defined the "bindRecyclerView" bindingAdapter function within the curly braces of a previous bindingAdapter function. This resulted in the "bindRecyclerView" function being eclipsed by the previous function and hence its setter cannot be seen from other files. When I removed it from within the previous function, everything worked fine.