找不到带参数的属性的设置器 [英] Cannot find the setter for attribute with parameter

查看:30
本文介绍了找不到带参数的属性的设置器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 BindingAdapter 处理 DataBinding.这是我的自定义方法.

I am working on DataBinding with BindingAdapter. Here is my custom method.

@BindingAdapter("{bind:fadevisible}")
public static void setFadeVisible(LinearLayout view, int visible) {
    Log.e("Bindings", "setFadeVisible: ");
}

在 xml 文件中我这样称呼它

And in xml file i am calling it like

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:fadevisible="@{1}"/>

但是显示错误

错误:任务:app:compileDebugJavaWithJavac"的执行失败.java.lang.RuntimeException:发现数据绑定错误.****/数据绑定错误 ****msg:在 android.widget.LinearLayout 上找不到参数类型为 int 的属性app:fadevisible"的设置器.文件:appsrcmain es-mainlayoutactivity_detail.xml地点:236:31 - 236:54****数据绑定错误****

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Cannot find the setter for attribute 'app:fadevisible' with parameter type int on android.widget.LinearLayout. file:appsrcmain es-mainlayoutactivity_detail.xml loc:236:31 - 236:54 **** data binding error ****

我已经检查了这个this 线程但不知何故它没有帮助我,正如你所看到的我正在从 xml 和 BindingAdapter 传递 int ,我也提到了 LinearLayoutint 值.

I have checked this and this thread but somehow it is not helping me, as you can see i am passing int from xml and in BindingAdapter also i have mentioned LinearLayout with int value.

即使我有另一种方法,只是参数不同并且工作正常

Even i have another method, where just parameters are different and its working fine

@BindingAdapter({"bind:image_round"}) 
public static void loadRoundImage(ImageView imageView, String url)

推荐答案

你的 @BindingAdapter 定义对我来说有点奇怪

Your @BindingAdapter definition looks a little bit odd to me

@BindingAdapter("{bind:fadevisible}")

这跟不一样

@BindingAdapter({"bind:fadevisible"})

@BindingAdapter("bind:fadevisible")

应该可以正常工作.

这篇关于找不到带参数的属性的设置器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆