title: Android - Conditional text value using Data Binding
body: <p>I want to set the text of my TextView conditionally to either one or the other.</p>
  
  <p>Android Data Binding documentation suggests that you can set the text conditionally if the text is a property of the view model. e.g.</p>
  
  <pre><code>android:text="@{user.displayName != null ? user.displayName : user.lastName}"
  </code></pre>
  
  <p>But is there any way to set the text from the strings.xml rather than adding it in my view model? I want something like this-</p>
  
  <pre><code>android:text="@{viewModel.expanded ? @string/collapse : @string/expand}"
  </code></pre>
  
  <p>The XML looks somewhat like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:bind="http://schemas.android.com/apk/res-auto"&gt;
     &lt;data class="TravellerInfoBinding"&gt;
        &lt;import type="android.view.View" /&gt;
        &lt;variable name="viewModel" type="com.myproject.viewmodel.TravellerInfoViewModel" /&gt;
  
     &lt;/data&gt;
     &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"&gt;
        &lt;ImageView android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center_vertical"
          android:src="@drawable/expandable_arrow_blue" /&gt;
  
        &lt;TextView style="@style/primary_pair_element_value" 
          android:layout_width="wrap_content"   
          android:layout_height="wrap_content" 
          android:text="@{viewModel.expanded ? @string/taxes_fees_detail : @string/hide_taxes_fees_detail}"
          android:textSize="12sp" /&gt;
  
     &lt;/LinearLayout&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>And this is my View Model-</p>
  
  <pre><code>package com.myproject.viewmodel;
  
  imports...
  
  public class TravellerInfoViewModel extends BaseObservable {
  
    @Bindable
    private final TaxDetailsViewModel taxDetailsViewModel;
  
    @Bindable
    private boolean expanded;
  
    Constructor....
  
    public boolean isExpanded() {
      return expanded;
    }
  
    public void setExpanded(boolean expanded) {
      this.expanded = expanded;
      notifyPropertyChanged(BR.expanded);
    }
  
    public void toggleExpanded() {
      setExpanded(!expanded);
    }
  
  }
  </code></pre>