Set drawable resource ID in android:src for ImageView using data binding in Android

后端 未结 15 2006
陌清茗
陌清茗 2020-12-04 09:27

I\'m trying to set drawable resource ID to android:src of ImageView using data binding

Here is my object:

public class Recipe implem         


        
15条回答
  •  独厮守ぢ
    2020-12-04 10:10

    This work for me. i would have add it to @hqzxzwb answer as comment but due to reputation limitations.

    I have this in my view Model

    var passport = R.drawable.passport
    

    Then in my xml, I have

    android:src="@{context.getDrawable(model.passort)}"
    

    And thats it

提交回复
热议问题