LoginSignup
12
5

More than 3 years have passed since last update.

[Android]ImageViewにリソースID (Resource) をデータバインディング (DataBinding)する

Last updated at Posted at 2019-01-24

ImageViewにDrawableのリソースID(Resource)をデータバインディング (DataBinding)したいときは
ImageViewのsrcにバインディングすると上手くいかない。

<ImageView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:src="@{viewmodel.resource}"/>

調べてみるとBindingAdapterを使ったサンプルなどが出るが、
使わなくてもimageResourceにBindingすれば良い

<ImageView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:imageResource="@{viewmodel.resource}"/>
12
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
5