title: Android data binding with conditional resources
body: <p>Here's a typical usage of Android's data-binding:</p>
  
  <pre><code>android:background="@{isError ? @color/red : @color/white}"
  </code></pre>
  
  <p>It gets harder when the state can adopt multiple values. <strong>Edit</strong>: using the status attribute in the method call was the only way to make it work:</p>
  
  <pre><code>android:background="@{Check.getStatusColor(check.status)}"
  </code></pre>
  
  <p>and define the static method (does not have @Bindable):</p>
  
  <pre><code>public int getStatusColor(int status) {
      switch (status.get()) {
          case STATUS_OK:
              return ContextCompat.getColor(context, R.color.success);
          case STATUS_WARNING:
              return ContextCompat.getColor(context, R.color.warning);
          case STATUS_ERROR:
              return ContextCompat.getColor(context, R.color.error);
          default:
              return ContextCompat.getColor(context, R.color.idle);
      }
  }
  </code></pre>
  
  <p>How can I achieve this, without putting nested ternary operators in the XML (which I don't find very elegant, btw), or without passing the <code>check.status</code> attribute?</p>
  
  <p>EDIT: Add XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;data&gt;
          &lt;import type="org.honorato.diagnostics.models.Check"/&gt;
          &lt;variable
              name="check"
              type="Check"/&gt;
      &lt;/data&gt;
      &lt;LinearLayout
          android:background="@android:color/white"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:minHeight="72dp"
          &gt;
  
          &lt;LinearLayout
              android:padding="16dp"
              android:layout_width="0dip"
              android:layout_weight="1"
              android:layout_height="wrap_content"
              android:orientation="vertical"&gt;
  
              &lt;TextView
                  android:text="@{check.title}"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:textColor="@android:color/primary_text_light"
                  android:textStyle="bold" /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;ImageView
              android:padding="16dp"
              android:src="@{check.getStatusDrawable(check.status)}"
              android:background="@{check.getStatusColor(check.status)}"
              android:layout_width="72dp"
              android:layout_height="match_parent"
              android:layout_gravity="center_vertical|center_horizontal" /&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/layout&gt;
  </code></pre>