title: Android recyclerView and data binding
body: <p>I make an Android application in Kotlin, and i want to get some information from the webserver and put in a recycler view using data binding. I use repository pattern, so each time i make a get request, i save the information in room database and get data from it with live data. For some reason my ryclerview show nothing, and i get no errors. The request work and i get the data but the recyclerview not working.
  My ViewModel:</p>
  <pre><code>class HomeViewModel(application: Application) : ViewModel() {
      private val availableTicketsRepo = AvailableTicketsRepository(getInstance(application))
  
      val tickets = availableTicketsRepo.availableTickets
  
      init {
          refreshDataFromRepository()
      }
  
      private fun refreshDataFromRepository() {
          viewModelScope.launch {
              try {
                  availableTicketsRepo.refreshAvailableTickets()
              } catch (ex: Exception) {
                  ex.message?.let { Resource.error(data = null, message = it) }
                  Log.i(&quot;Home&quot;, &quot;*** Eccezione: ${ex} ***&quot;)
              }
          }
      }
  </code></pre>
  <p>My fragment class (with adapter and viewholder):</p>
  <pre><code>package com.example.ticketapp.ui.home
  
  class HomeFragment : Fragment() {
  
      private val viewModel: HomeViewModel by lazy {
          val activity = requireNotNull(this.activity) {
              &quot;You can only access the viewModel after onActivityCreated()&quot;
          }
          ViewModelProvider(this, HomeViewModel.Factory(activity.application))
              .get(HomeViewModel::class.java)
      }
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View {
          val binding = DataBindingUtil.inflate&lt;FragmentHomeBinding&gt;(
              inflater,
              R.layout.fragment_home,
              container,
              false
          )
  
          binding.lifecycleOwner = this
          binding.viewModel = viewModel
  
          binding.availableTicketsList.adapter = AvailableTicketsAdapter()
  
  
          return binding.root
      }
  }
  
  class AvailableTicketsAdapter() :
      ListAdapter&lt;AvailableTicket, AvailableTicketsAdapter.AvailableTicketViewHolder&gt;(DiffCallback) {
  
      class AvailableTicketViewHolder(private var binding: AvailableTicketItemsBinding) :
          RecyclerView.ViewHolder(binding.root) {
          fun bind(tickets: AvailableTicket) {
              binding.ticket = tickets
              binding.executePendingBindings()
          }
      }
  
      companion object DiffCallback : DiffUtil.ItemCallback&lt;AvailableTicket&gt;() {
          override fun areItemsTheSame(oldItem: AvailableTicket, newItem: AvailableTicket): Boolean {
              return oldItem === newItem
          }
  
          override fun areContentsTheSame(
              oldItem: AvailableTicket,
              newItem: AvailableTicket
          ): Boolean {
              return oldItem.Id == newItem.Id
          }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AvailableTicketViewHolder {
          return AvailableTicketViewHolder(
              AvailableTicketItemsBinding.inflate(
                  LayoutInflater.from(
                      parent.context
                  )
              )
          )
      }
  
  
      override fun onBindViewHolder(holder: AvailableTicketViewHolder, position: Int) {
          val tickets = getItem(position)
          holder.bind(tickets)
      }
  }
  </code></pre>
  <p>My repository:</p>
  <pre><code>class AvailableTicketsRepository(private val database: TicketDatabase) {
      val availableTickets: LiveData&lt;List&lt;AvailableTicket&gt;&gt; =
          Transformations.map(database.ticketDatabaseDao.getAvailableTickets()) {
              it.asDomainModel()
          }
  
  
      suspend fun refreshAvailableTickets() {
          withContext(Dispatchers.IO) {
              val tickets = RetrofitBuilder.apiService.getAvailableTickets()
              database.ticketDatabaseDao.insertAllAvailableTickets(tickets.map { it.asDataBaseModel() })
          }
      }
  }
  </code></pre>
  <p>The xml for items in recylerview:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;
  
      &lt;data&gt;
          &lt;import type=&quot;android.view.View&quot;/&gt;
          &lt;variable
              name=&quot;ticket&quot;
              type=&quot;com.example.ticketapp.model.AvailableTicket&quot; /&gt;
      &lt;/data&gt;
  
      &lt;androidx.constraintlayout.widget.ConstraintLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;&gt;
  
          &lt;TextView
              android:id=&quot;@+id/titleText&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:ellipsize=&quot;end&quot;
              android:maxLength=&quot;50&quot;
              android:text=&quot;@{ticket.title}&quot;
              android:singleLine=&quot;true&quot;
              android:textAlignment=&quot;center&quot;
              android:textSize=&quot;16sp&quot;
              android:textStyle=&quot;bold&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toTopOf=&quot;parent&quot;
              tools:text=&quot;Titolo di max 50 caratteri per non uscire dalla riga&quot; /&gt;
  
  
          &lt;TextView
              android:id=&quot;@+id/customerText&quot;
              android:layout_width=&quot;160dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;5dp&quot;
              android:textSize=&quot;14sp&quot;
              android:text=&quot;@{ticket.customer}&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/titleText&quot;
              tools:text=&quot;ESEMPIO DI UN REFERENTE&quot; /&gt;
  
          &lt;TextView
              android:id=&quot;@+id/dateText&quot;
              android:layout_width=&quot;80dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;5dp&quot;
              android:textAlignment=&quot;textEnd&quot;
              android:textSize=&quot;14sp&quot;
              android:text=&quot;@{ticket.date_Time}&quot;
              app:layout_constraintBaseline_toBaselineOf=&quot;@+id/customerText&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/titleText&quot;
              tools:text=&quot;20/01/2021 10:00:00&quot; /&gt;
  
          &lt;ImageView
              android:id=&quot;@+id/warningImg&quot;
              style=&quot;@style/iconImg&quot;
              android:layout_marginTop=&quot;20dp&quot;
              android:visibility=&quot;@{ticket.triangle ? View.VISIBLE : View.GONE}&quot;
              android:foregroundGravity=&quot;center&quot;
              app:layout_constraintEnd_toStartOf=&quot;@+id/dateText&quot;
              app:layout_constraintStart_toEndOf=&quot;@+id/customerText&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/titleText&quot;
              app:srcCompat=&quot;@drawable/ic_warning&quot; /&gt;
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  &lt;/layout&gt;
  </code></pre>
  <p>XML of ryclerview:</p>
  <pre><code>&lt;androidx.recyclerview.widget.RecyclerView
             android:id=&quot;@+id/availableTicketsList&quot;
             android:layout_width=&quot;match_parent&quot;
             android:layout_height=&quot;wrap_content&quot;
             android:paddingStart=&quot;10dp&quot;
             android:paddingEnd=&quot;10dp&quot;
             app:layoutManager=&quot;androidx.recyclerview.widget.LinearLayoutManager&quot;
             app:layout_constraintEnd_toEndOf=&quot;parent&quot;
             app:layout_constraintStart_toStartOf=&quot;parent&quot;
             app:layout_constraintTop_toBottomOf=&quot;@+id/toolbar&quot;
             tools:listitem=&quot;@layout/available_ticket_items&quot; /&gt;
  </code></pre>
  <p>My Model class:</p>
  <pre><code>@Parcelize
  data class AvailableTicket (
     val Id: Int,
     val Title: String,
     val Description: String,
     val Date_Time: String,
     val Customer: String,
     val Field: String,
     val Category: String,
     val Color: String,
     val Author: String,
     val Triangle: Boolean,
     val MyPriority: String
  ): Parcelable
  </code></pre>