Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding Adapter not working properly

I have a hard time making @BindingAdapter to work in my project.

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

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. namespace app is unbound. So what am i missing. I tried following https://medium.com/google-developers/android-data-binding-custom-setters-55a25a7aea47#.6ygaiwooh and see how they set bindingAdapter. But there is something i have missed

like image 206
Jemil Riahi Avatar asked Jan 08 '17 13:01

Jemil Riahi


People also ask

What is the purpose of a binding adapter?

Binding adapters are responsible for making the appropriate framework calls to set values. One example is setting a property value like calling the setText() method. Another example is setting an event listener like calling the setOnClickListener() method.

What is an inverse binding adapter?

android.databinding.InverseBindingAdapter. InverseBindingAdapter is associated with a method used to retrieve the value for a View when setting values gathered from the View.


1 Answers

I encountered the same problem, I missed to bind layout using:

DataBindingUtil.setContentView(activity, layoutResId);
like image 135
Swapnil Avatar answered Sep 24 '22 02:09

Swapnil