The binding adapter is not working properly

It’s hard @BindingAdapterfor me to do to work in my project.

@BindingAdapter("imageUrl")
public static void setImageUrl(ImageView imageView, String url) {
    Log.d("TEST","URL: " + url);
}

The above code shows how it is implemented in my ViewModel. Nothing special.

    <ImageView
        android:id="@+id/image_holder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:layout_below="@id/profile_container"
        app:imageUrl="@{item.imageUrl}"
        tools:src="@drawable/placeholder_image"/>

This does not work. the namespace application is unrelated. So what I am missing. I tried following https://medium.com/google-developers/android-data-binding-custom-setters-55a25a7aea47#.6ygaiwooh and see how they install the bindingAdapter. But I missed something

+4
source share
3 answers

I ran into the same problem, I skipped layout binding using:

DataBindingUtil.setContentView(activity, layoutResId);
+1
source

"" .

Adapter:

@BindingAdapter("bind:imageUrl")
public static void setImageUrl(ImageView imageView, String imageUrl) {
     Log.d("TEST","URL: " + imageUrl);
}

:

<ImageView
    android:id="@+id/image_holder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    android:layout_below="@id/profile_container"

    bind:imageUrl="@{item.imageUrl}"

    tools:src="@drawable/placeholder_image"/>

"" "bind"

0

Try

@BindingAdapter({"bind:imageUrl"})
-1
source

Source: https://habr.com/ru/post/1666140/


All Articles