Set drawable resource ID in android:src for ImageView using data binding in Android
<p><strong>I'm trying to set drawable resource ID to android:src of ImageView using data binding</strong></p>

<p>Here is my object:</p>

<pre><code>public class Recipe implements Parcelable {
    public final int imageResource; // resource ID (e.g. R.drawable.some_image)
    public final String title;
    // ...

    public Recipe(int imageResource, String title /* ... */) {
        this.imageResource = imageResource;
        this.title = title;
    }

    // ...
}
</code></pre>

<p>Here is my layout:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"&gt;

    &lt;data&gt;
        &lt;variable
            name="recipe"
            type="com.example.android.fivewaystocookeggs.Recipe" /&gt;
    &lt;/data&gt;

    &lt;!-- ... --&gt;

    &lt;ImageView
        android:id="@+id/recipe_image_view"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        android:src="@{recipe.imageResource}" /&gt;

    &lt;!-- ... --&gt;

&lt;/layout&gt;
</code></pre>

<p>And finally, activity class:</p>

<pre><code>// ...

public class RecipeActivity extends AppCompatActivity {

    public static final String RECIPE_PARCELABLE = "recipe_parcelable";
    private Recipe mRecipe;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mRecipe = getIntent().getParcelableExtra(RECIPE_PARCELABLE);
        ActivityRecipeBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_recipe);
        binding.setRecipe(mRecipe);
    }

    // ...

}
</code></pre>

<p>It doesn't display image at all. What am I doing wrong?</p>

<p>BTW, it was perfectly working with standard way:</p>

<pre><code>@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipe);

    final ImageView recipeImageView = (ImageView) findViewById(R.id.recipe_image_view);
    recipeImageView.setImageResource(mRecipe.imageResource);

}
</code></pre>