1

我正在尝试使用 GridLayoutManager 实现 RecyclerView,但我被卡住了。我收到错误:


If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
Open File"

当我试图编译时。“打开文件”为我提供了 xml 回收器视图声明。

这是我的 BindingAdapter:

    @BindingAdapter("listData")
    fun bindRecyclerView(recyclerView: RecyclerView,
                         data: List<MarsPropertyData>?) {
        val adapter = recyclerView.adapter as PhotoGridAdapter
        adapter.submitList(data)
    }

我如何称呼上述内容:

      <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}"
            />

这是我的属性变量:

val properties: LiveData<List<MarsPropertyData>>

我知道 IDE 抱怨数据类型,我的properties var 它是LiveData<List<MarsPropertyData>>,里面BindingAdapter只有普通的 List,但我看到了来自 google 的示例,其中逻辑以相同的方式制作并且运行良好。

是的,我添加了'kotlin-kapt'插件,我还有另一个 BindingAdapter 可以正常工作。

4

0 回答 0