相关疑难解决方法(0)

Android数据绑定:Kotlin中的@BindingAdapter无法识别lambdas

这是我的BindingAdapter:

@BindingAdapter(value = *arrayOf("bind:commentsAdapter", "bind:itemClick", "bind:avatarClick", "bind:scrolledUp"), requireAll = false)    
fun initWithCommentsAdapter(recyclerView: RecyclerView, commentsAdapter: CommentsAdapter,
                        itemClick: (item: EntityCommentItem) -> Unit,
                        avatarClick: ((item: EntityCommentItem) -> Unit)?,
                        scrolledUp: (() -> Unit)?) {
    //Some code here
}
Run Code Online (Sandbox Code Playgroud)

initWithCommentsAdapter 是一个顶级功能

这是我的布局(必不可少的部分):

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:bind="http://schemas.android.com/apk/res-auto">

           <data>
               <variable
                   name="viewModel"
                   type="some.example.path.CommentsViewModel"/>
               <variable
                   name="commentsAdapter"
                   type="some.example.path.CommentsAdapter"/>
           </data>

           <android.support.v7.widget.RecyclerView
                ...
                bind:avatarClick="@{(item) -> viewModel.avatarClick(item)}"
                bind:itemClick="@{viewModel::commentClick}"
                bind:commentsAdapter="@{commentsAdapter}"
                bind:isVisible="@{viewModel.commentsVisibility}"
                bind:scrolledUp="@{() -> viewModel.scrolledUp()}"
            />
</layout>
Run Code Online (Sandbox Code Playgroud)

当我在布局中使用kotlin方法调用分配lambda时,我在构建期间出现了这样的错误:

e: java.lang.IllegalStateException: failed to analyze: 
java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:cannot find …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-databinding

10
推荐指数
2
解决办法
1391
查看次数

标签 统计

android ×1

android-databinding ×1

kotlin ×1