title: Data binding List of custom items
body: <p>How do I bind a List of custom items to a ListView or a RecyclerView? Using only Android <strong>DEFAULT</strong> DataBinding (no external library)  </p>
  
  <pre><code>&lt;layout&gt;
      &lt;data&gt;
          &lt;import type="java.util.List"/&gt;
          &lt;variable name="listOfString" type="List&amp;lt;String&gt;"/&gt;
      &lt;/data&gt;
  
      &lt;ListView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:?????="@{listOfString}/&gt;  &lt;!--Like we have ItemsSource in WPF--&gt;
  
  &lt;/layout&gt;
  </code></pre>
  
  <p>I came from WPF background, in which there is a ItemTemplate option. Using ItemTemplate you can map data to your view purely through XML. Something like:</p>
  
  <pre><code>&lt;ListView ItemsSource="{Binding Path=UserCollection}"&gt;
    &lt;ListView.ItemTemplate&gt;
      &lt;!--Populate template with each user data--&gt;
      &lt;DataTemplate&gt;
        &lt;WrapPanel&gt;
          &lt;!--Bind to user.Name--&gt;
          &lt;TextBlock Text="{Binding Name}" FontWeight="Bold" /&gt;
          &lt;TextBlock Text="{Binding Age}" FontWeight="Bold" /&gt;
          &lt;TextBlock Text="{Binding Mail}" /&gt;
        &lt;/WrapPanel&gt;
      &lt;/DataTemplate&gt;
    &lt;/ListView.ItemTemplate&gt;
  &lt;/ListView&gt;
  </code></pre>