title: Android recyclerView data binding adapter data
body: <p>I am implementing a <code>Recycler View</code> and its respective <code>adapter</code> using <code>Android Data Binding</code>. The problem is that in all the tutorials I have seen, they initialize the data of the adapter with a <code>Collection</code> of <code>View model</code> class, like this:</p>
  
  <pre><code>public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt; implements View.OnClickListener {
  
  private ArrayList&lt;ViewModel&gt; items;
  
  public RecyclerViewAdapter(ArrayList&lt;ViewModel&gt; items) {
      this.items = items;
  }
  
  .....
  }
  </code></pre>
  
  <p>But the data I want to pass to the <code>Recycler View</code> is a <code>Collection</code> of <code>records</code> from my <code>database</code>:</p>
  
  <pre><code>private ArrayList&lt;Record&gt; items;
  </code></pre>
  
  <p>How can I do that??</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>li_item.xml</strong></p>
  
  <pre><code>&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"&gt;
  
  &lt;data&gt;
      &lt;variable
          name="report"
          type="viewmodel.ReportVM"/&gt;
  &lt;/data&gt;
  
  ....
  
  &lt;TextView
          android:id="@+id/tv_report_name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:textSize="18sp"
          android:paddingBottom="6dp"
          android:text="@{report.name}"
          tools:text="Report 1"
          /&gt;
  
  ....
  </code></pre>
  
  <p><strong>ADAPTER</strong></p>
  
  <pre><code>    public class ReportRVAdapter extends RecyclerView.Adapter&lt;ReportRVAdapter.ReportViewHolder&gt; {
  
  private List&lt;ReportDb&gt; data;
  
  
  public ReportRVAdapter(final List&lt;ReportDb&gt; reportData) {
      this.data = reportData;
  }
  
  @Override
  public ReportRVAdapter.ReportViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
      View v = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.li_item, parent, false);
      return new ReportViewHolder(v);
  }
  
  @Override
  public void onBindViewHolder(final ReportViewHolder holder, final int position) {
      ReportDb item = data.get(position);
  
      holder.getBinding().setVariable(BR.name, item.getName());
      holder.getBinding().setVariable(BR.contractor, item.getContractor());
  
      //make binding happen immediately
      holder.getBinding().executePendingBindings();
  }
  
  @Override
  public int getItemCount() {
      return data == null ? 0 : data.size();
  }
  
  
  public class ReportViewHolder extends RecyclerView.ViewHolder {
      private ViewDataBinding binding;
  
      public ReportViewHolder(final View rowView) {
          super(rowView);
  
          binding = DataBindingUtil.bind(rowView);
      }
  
      public ViewDataBinding getBinding() {
          return binding;
      }
  }
  }
  </code></pre>
  
  <p><strong>MODEL VIEW</strong> </p>
  
  <pre><code>public class ReportVM extends BaseObservable {
  
  public String name;
  public String contractor;
  
  public ReportVM() {
  }
  
  @Bindable
  public String getName() {
      return name;
  }
  
  public void setName(final String name) {
      this.name = name;
  }
  
  @Bindable
  public String getContractor() {
      return contractor;
  }
  
  public void setContractor(final String contractor) {
      this.contractor = contractor;
  }
  }
  </code></pre>