title: No Data with RecyclerView, Data Binding and ViewModel
body: <p>New to Android development and trying to wrap my head around the latest Architecture Components.  Using Android Studio 3.2, Room, LiveData, ViewModel, Data Binding and RecyclerView and I’ve been fighting with Data Binding for days.  I have a fragment in my activity and the RecyclerView portion that should be showing data from my ViewModel/Query is blank/empty.  The Log.d in getItemCount for the Adapter shows zero items even though the related Room query is valid and returns items.</p>
  
  <p>Please hit me with the clue stick and let me know what I am missing.  The relevant portions of my code:</p>
  
  <p>Entity and Dao</p>
  
  <pre><code>import org.threeten.bp.Instant
  
  data class ActionDetails(val time: Instant,
                       val firstName: String,
                       ... )
  
  @Query("SELECT time, first_name as firstName...")
  fun liveStatus(): LiveData&lt;List&lt;ActionDetails&gt;&gt;
  </code></pre>
  
  <p>Fragment Class</p>
  
  <pre><code>class MainFragment : Fragment() {
  ...
  private lateinit var viewModel: MainViewModel
  private lateinit var adapter: ViewAdapter
  
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                            savedInstanceState: Bundle?): View {
      val binding = MainFragmentBinding.inflate(inflater, container, false)
      val context = context ?: return binding.root
  
      val factory = Utilities.provideMainViewModelFactory(context)
      viewModel = ViewModelProviders.of(this, factory).get(MainViewModel::class.java)
  
      adapter = ViewAdapter(listOf())
  
      binding.apply {
          rvActionDetails.setHasFixedSize(true)
          rvActionDetails.layoutManager = LinearLayoutManager(context)
          rvActionDetails.adapter = adapter
          vm = viewModel
          setLifecycleOwner(this@MainFragment)
      }
  
      return binding.root
  }
  </code></pre>
  
  <p>ViewModel</p>
  
  <pre><code>class MainViewModel(private val repository: DataRepository) : ViewModel() {
      val actions: LiveData&lt;List&lt;ActionDetails&gt;&gt; = repository.liveStatus()
  }
  </code></pre>
  
  <p>Adapter</p>
  
  <pre><code>import ...FragmentActionDetailBinding
  
  class ViewAdapter(private val actions: List&lt;ActionDetails&gt;) : RecyclerView.Adapter&lt;ViewAdapter.ViewHolder&gt;() {
  private val TAG = this::class.java.simpleName
  
  class ViewHolder(val binding: FragmentActionDetailBinding) : RecyclerView.ViewHolder(binding.root) {
      fun bind(action: ActionDetails) {
              binding.apply {
              vm = action
              executePendingBindings()
              }
      }
  }
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      val inflater = LayoutInflater.from(parent.context)
      val binding = FragmentActionDetailBinding.inflate(inflater, parent, false)
      return ViewHolder(binding)
  }
  
  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      holder.bind(actions[position])
  }
  
  override fun getItemCount(): Int {
      Log.d(TAG, "Adapter has ${actions.size} items!")
      return actions.size
  }
  }
  </code></pre>
  
  <p>Main Fragment</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="vm" type=".MainViewModel" /&gt;
  &lt;/data&gt;
  
  &lt;androidx.constraintlayout.widget.ConstraintLayout
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainFragment" &gt;
      ...
      &lt;androidx.recyclerview.widget.RecyclerView
          android:id="@+id/rv_action_details"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
          tools:listitem="@layout/fragment_action_detail" /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Fragment XML</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="vm" type=".ActionDetails" /&gt;
  &lt;/data&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      tools:context=".ActionDetailFragment" &gt;
  
      &lt;TextView
          android:id="@+id/first_name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@{vm.firstName}"
          tools:text="John"/&gt;
      ...
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>