2

I tried to do some analog of example from here: http://www.mutualmobile.com/posts/using-data-binding-api-in-recyclerview And everything works correct except image url binding. I received error: 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.imageUrl' with parameter type java.lang.String. file:D:\Projects\app\src\main\res\layout\view_simple_item.xml loc:43:32 - 43:47 ****\ data binding error ****

My Layout:

...
<data>       
    <variable
        name="item"
        type="com.example.Item" />
</data>
...

<ImageView
            android:id="@+id/iv_item"
            app.imageUrl="@{item.imageUrl}"
            ... />
...

My adapter:

package com.example.adapters;

import android.databinding.BindingAdapter;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;

public class CustomBindingAdapter {
    @BindingAdapter("bind:imageUrl")
    public static void loadImage(ImageView imageView, String url) {
        Picasso.with(imageView.getContext()).load(url).into(imageView);
    }
}
1
  • I know I'm late, but just drop the "bind:" and make it: @BindingAdapter("imageUrl") that's how I add custom ones and works Commented Oct 21, 2017 at 18:01

3 Answers 3

2

Found my problem. Instead of:

app.imageUrl="@{item.imageUrl}"

Must be:

app:imageUrl="@{item.imageUrl}"
Sign up to request clarification or add additional context in comments.

3 Comments

What's the difference?
app COLON instead of app DOT Don't worry. I looked at this for 10 minutes until I was cross eyed.
won't compile for me says it can't find CustomBindingAdapter .imageUrl
0

Set the argument of BindingAdapter annotation to "app:imageUrl". So you must have this:

@BindingAdapter("app:imageUrl")

instead of this:

@BindingAdapter("bind:imageUrl")

And also what @Alexander Myznikov said - change app.imageUrl to app:imageUrl

Comments

0

Only try to rename the reference inside of the @BindingAdapter

@BindingAdapter({"bind:image_url"})
    public static void loadImage(ImageView imageView, String url) {
        Picasso.with(imageView.getContext()).load(url).into(imageView);
    }

And in your layout this:

...
<data>       
    <variable
        name="item"
        type="com.example.Item" />
</data>
...

<ImageView
            android:id="@+id/iv_item"
            app:image_url="@{item.imageUrl}"
            ... />
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.