title: Android spinner Data Binding using XML and show the selected values
body: <p>I am using the new android data binding and it works great. I am able to perform data binding using EditText, TextView, Radio and checkbox. Now, I am not able to do the databinding in spinner.</p>
  
  <p>Found some clue in below link:
  <a href="https://stackoverflow.com/questions/34962179/android-spinner-data-binding-with-xml-layout">Android spinner data binding with xml layout</a></p>
  
  <p>But, still not able to find the solution. Also need to perform the two way databinding. Should reflect the spinner data selected value.</p>
  
  <p>Can someone please show me with an example?</p>
  
  <p>Here is my <code>xml</code> code:</p>
  
  <pre><code>&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/tools"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;data&gt;
          &lt;import type="android.view.View" /&gt;
          &lt;variable
              name="viewModel"
              type="com.ViewModels.model" /&gt;
      &lt;/data&gt;
  
       &lt;Spinner
                      android:id="@+id/assessmemt_spinner"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_alignParentRight="true"
                      android:layout_margin="@dimen/carview_margin"
                      android:layout_toRightOf="@+id/text_bp"
                      android:drawSelectorOnTop="true"
                      android:spinnerMode="dropdown"
                     android:visibility="@{viewModel.type.equals(@string/spinner_type)?  View.VISIBLE : View.GONE}" /&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>View Model:</p>
  
  <pre><code> public class AssessmentGetViewModel {
      private String valueWidth;
      private ArrayList&lt;String&gt; values;
      private String type;
      public String getValueWidth() { return this.valueWidth; }
      public void setValueWidth(String valueWidth) { this.valueWidth = valueWidth; }
      public ArrayList&lt;String&gt; getvalues() { return this.values; }
      public void setvalues(ArrayList&lt;String&gt; values) { this.values = values; }
      public String gettype() { return this.type; }
      public void settype(String type) { this.type = type; }
      }
  </code></pre>