liangfeidotme / MasteringAndroidDataBinding

A comprehensive tutorial for Android Data Binding
http://liangfei.me
MIT License
2.59k stars 497 forks source link

app:imageUrl="@{imageUrl}能运行起来吗? #3

Open pengwei1024 opened 9 years ago

pengwei1024 commented 9 years ago

@BindingAdapter({"bind:imageUrl", "bind:error"}) public static void loadImage(ImageView view, String url, Drawable error) { Picasso.with(view.getContext()).load(url).error(error).into(view); } 我这样写提示TextView没有imageUrl方法报错。

liangfeidotme commented 9 years ago

imageUrl 是利用 data binding 适配的属性,编译会出错吗?

pengwei1024 commented 9 years ago

报错如下:annot find the setter for attribute 'imageUrl' on android.widget.ImageView with parameter type java.lang.String.

liangfeidotme commented 9 years ago

几个checkpoint

  1. 代码没改过吧?
  2. imageUrl 的 namespace 不是 android
  3. AS 升级到1.3
pengwei1024 commented 9 years ago

环境我都配置好了,就这个东西编译不过。我对这种写法也觉得特别奇怪,app:imageUrl="@{url}"这样写法不是会去找ImageView属性吗?而且就对一个静态方法添加注解,这样是不是太莫名其妙了?楼主你能运行出来并加载图片么?

liangfeidotme commented 9 years ago

代码运行没问题,你是跑的我的代码吗

zhangxiaang commented 9 years ago

to @pengwei1024 可以把你的attribute_setters.xml文件贴出来看看吗?我猜测是否是xml文件有改动?

ysmintor commented 8 years ago
    @BindingAdapter({"imageUrl", "error"})
    public static void loadImage(ImageView view, String url, Drawable error) {
        Log.d(App.TAG, "load image");
        Picasso.with(view.getContext()).load(url).error(error).into(view);
    }

楼主@BindingAdapter({"bind:imageUrl", "bind:error"})中多了bind,我也不知道为什么。