How to set Image resource to ImageView using DataBinding [duplicate]

I tried this, and it works for me (buildToolsVersion: 24.0.1):

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_margin="8dp"
    android:scaleType="centerInside"
    app:imageResource="https://stackoverflow.com/questions/34607028/@{item.avatarResId}"/>

just use app:imageResource to replace android:src, android:src="https://stackoverflow.com/questions/34607028/@{item.avatarResId}" doesn’t works else define a custom @BindAdapter("android:src") for it.

but use app:imageResource doesn’t need define a @BindAdapter additionally, because the ImageView has a method called setImageResource(), when you use app:imageResource, it will call setImageResource() automatically.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)