Android DataBinding 自定义绑定适配器警告 [英] Android DataBinding Custom Binding Adapter Warning

查看:44
本文介绍了Android DataBinding 自定义绑定适配器警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了来自官方 Android 开发者网站的自定义绑定适配器的数据绑定文档,用于图像加载:

解决方案

我相信在 BindingAdapter 注释中确实忽略了命名空间.如果您使用任何命名空间前缀,无论它是否与布局中使用的前缀匹配,都会出现警告.如果省略命名空间,如下所示:

@BindingAdapter({"imageUrl"})

...警告不会发生.

我怀疑存在警告是为了提醒我们在将字符串用作注释实现中的键之前命名空间已被剥离.当您考虑布局可以自由声明他们想要的任何命名空间时,这是有道理的,例如app:bind:foo:,并且注释需要适用于所有这些情况.

I followed the data binding documentation for Custom Binding Adapter for image loading from official Android Developers site: http://developer.android.com/tools/data-binding/guide.html

After successfully compiling the code I get a warning which is:

Warning:Application namespace for attribute bind:imageUrl will be ignored.

My Code is as follow:

@BindingAdapter({"bind:imageUrl"})
    public static void loadImage(final ImageView imageView, String url) {
        imageView.setImageResource(R.drawable.ic_launcher);
        AppController.getUniversalImageLoaderInstance().displayImage(url, imageView);
    }

Why this warning is generated?

A screenshot is also attached...

解决方案

I believe the namespace is truly ignored in the BindingAdapter annotation. The warning occurs if you use any namespace prefix, regardless of whether it matches the one used in your layout or not. If you omit the namespace, like so:

@BindingAdapter({"imageUrl"})

...the warning doesn't occur.

I suspect the warning exists to alert us the namespace is stripped off before the string is used as a key in the annotation's implementation. Which makes sense when you consider layouts are free to declare whatever namespaces they want, e.g. app: or bind: or foo:, and the annotation needs to work across all those cases.

这篇关于Android DataBinding 自定义绑定适配器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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