我正在使用 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"的设置器.文件:appsrcmaines-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:appsrcmaines-mainlayoutactivity_detail.xml loc:236:31 - 236:54 **** data binding error ****
我已经检查了这个和this 线程但不知何故它没有帮助我,正如你所看到的我正在从 xml 和 BindingAdapter 传递 int ,我也提到了 LinearLayout 和 int 值.
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")应该可以正常工作.
更多推荐
找不到带参数的属性的设置器
发布评论