Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

<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.

Anybody help ?

like image 770
Jack Le Avatar asked Dec 15 '17 07:12

Jack Le


2 Answers

Change this line . Hope this Help.

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

To

android:onClick="@{(view) -> callback.onUserClick(user)}">
like image 156
Dharmishtha Avatar answered Sep 19 '22 23:09

Dharmishtha


I had the same problem. I deleted the ".gradle" folder and clicked "Rebuild Project".

It worked for me.

like image 40
Suphakrit Nakhabat Avatar answered Sep 19 '22 23:09

Suphakrit Nakhabat