[英]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.