简体   繁体   English

在 android.widget.RelativeLayout 上找不到参数类型为 lambda 的属性“android:onClick”的设置器

[英]Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.RelativeLayout

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
    <variable name="user"
        type="com.daimler.user.persistence.User"/>
    <variable name="callback"
        type="com.daimler.user.ui.UserClickCallback"/>
</data>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:clickable="true"
    android:paddingBottom="@dimen/row_padding"
    android:paddingLeft="@dimen/activity_margin"
    android:paddingRight="@dimen/activity_margin"
    android:paddingTop="@dimen/row_padding"
    android:onClick="@{() -> callback.onUserClick(user)}">

public class UserClickCallback {

   public void onUserClick(User v) {

   }
}

I wrote code like this, it looks okay but it shows error:我写了这样的代码,看起来不错,但显示错误:

Error:(36, 28) Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.RelativeLayout.错误:(36, 28) 在 android.widget.RelativeLayout 上找不到参数类型为 lambda 的属性“android:onClick”的设置器。

Anybody help ?有人帮忙吗?

Change this line .改变这一行。 Hope this Help.希望这有帮助。

android:onClick="@{() -> callback.onUserClick(user)}">

To

android:onClick="@{(view) -> callback.onUserClick(user)}">

I had the same problem.我有同样的问题。 I deleted the " .gradle " folder and clicked " Rebuild Project ".我删除了“ .gradle ”文件夹并单击“ Rebuild Project ”。

It worked for me.它对我有用。

I got the answer.我得到了答案。 The default binding adapter doesn't work so i added app:onclick binding:默认绑定适配器不起作用,所以我添加了 app:onclick 绑定:

@BindingAdapter({"app:onClick"})
public static void setOnClick(View view, View.OnClickListener clickListener) {
    view.setOnClickListener(clickListener);
    view.setClickable(true);
}

Then i changed the xml like this:然后我像这样改变了xml:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:paddingBottom="@dimen/row_padding"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/row_padding"
app:onClick="@{() -> callback.onUserClick(user)}">

将“android:onClick”更改为“android:onClickListener”,它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法转换为 android.widget.RelativeLayout - cannot be cast to android.widget.RelativeLayout android.widget.RelativeLayout无法转换为android.widget.EditText - android.widget.RelativeLayout cannot be cast to android.widget.EditText 无法将Android.widget.RelativeLayout强制转换为android.widget.ImageView - Android.widget.RelativeLayout cannot be cast to android.widget.ImageView 在 android.widget.ImageView 上找不到参数类型为 int 的属性“android:layout_width”的设置器 - Cannot find the setter for attribute 'android:layout_width' with parameter type int on android.widget.ImageView android.widget.RelativeLayout无法转换为android.widegt.ImageButton - android.widget.RelativeLayout cannot be cast to android.widegt.ImageButton Null 不能强制转换为非空类型 android.widget.RelativeLayout - Null cannot be cast to non-null type android.widget.RelativeLayout 在android.widget.TextView上找不到参数类型为android.graphics.drawable.Drawable的属性“ android:drawable”的设置器 - Cannot find the setter for attribute 'android:drawable' with parameter type android.graphics.drawable.Drawable on android.widget.TextView 找不到参数类型为int的属性“ android:textColorHint”的设置器 - Cannot find the setter for attribute 'android:textColorHint' with parameter type int Android java.lang.ClassCastException:无法将android.widget.RelativeLayout强制转换为android.widget.EditText - Android java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.EditText 造成原因:java.lang.ClassCastException:android.widget.RelativeLayout无法转换为android.widget.TextView - Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM