相关疑难解决方法(0)

监听器绑定; 找不到塞特犬

我正在尝试实现侦听器绑定,但是当我运行我的代码时,我收到以下错误:

Caused by: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.Button. file:~/GithubBrowser/app/src/main/res/layout/loading_state.xml loc:30:31 - 30:52 ****\ data binding error ****
Run Code Online (Sandbox Code Playgroud)

这是有问题的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>
        <import type="com.example.app.data.model.Resource"/>
        <import type="com.example.app.data.model.Status"/>
        <variable name="resource" type="Resource"/>
        <variable name="callback" type="com.example.app.ui.common.RetryCallback"/>
    </data>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:padding="@dimen/default_margin">

        <Button android:id="@+id/retry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/retry"
            android:onClick="@{() -> callback.retry()}"/>

    </LinearLayout>

</layout>
Run Code Online (Sandbox Code Playgroud)

这是RetryCallback布局中引用的接口:

package com.example.app.ui.common

interface RetryCallback {

    fun …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-databinding

27
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-databinding ×1

kotlin ×1