title: How to display items loading while data is being fetched from Firebase android kotlin
body: <p>I have a <code>RecyclerView</code> and my <code>Fragment</code>. I am getting data from <code>Firebase Realtime Database</code> into a RecyclerView.</p>
  <p>I need to make it so that while the data is loading, I see some kind of loading effect. How can i do this?</p>
  <p>Code from my <code>Fragment:</code></p>
  <pre><code>private var _binding: FragmentDayDetailBinding? = null
  private val binding get() = _binding!!
  
  private var ref: DatabaseReference? = null
  private lateinit var adapter: DayDetailAdapter
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View {
      _binding = FragmentDayDetailBinding.inflate(inflater, container, false)
  
      setupRecyclerView()
      initDatabase()
  
      return binding.root
  }
  
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
  
      readFromDatabase()
  }
  
  private fun setupRecyclerView() {
      adapter = DayDetailAdapter()
      binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
      binding.recyclerView.adapter = adapter
  }
  
  private fun initDatabase() {
      FirebaseApp.initializeApp(requireContext())
  
      ref = FirebaseDatabase.getInstance()
          .getReference(&quot;IMIT&quot;)
          .child(&quot;groups&quot;)
  }
  
  private fun readFromDatabase() {
      ref?.addValueEventListener(object: ValueEventListener {
          override fun onDataChange(snapshot: DataSnapshot) {
              if (snapshot.exists()) {
  
                  val list = ArrayList&lt;Day&gt;()
  
                  for (daySnapshot in snapshot.children) {
                      val day = daySnapshot.getValue(Day::class.java)
  
                      list.add(day!!)
                  }
  
                  adapter.submitList(list)
  
              } else {
                  binding.apply {
                      lrDbEmpty.visibility = View.VISIBLE
                      recyclerView.visibility = View.INVISIBLE
                  }
              }
          }
  
          override fun onCancelled(error: DatabaseError) {
  
          }
      })
  }
  
  override fun onDestroyView() {
      super.onDestroyView()
      _binding = null
  }
  </code></pre>
  <p>Code from <code>RecyclerView Adapter:</code></p>
  <pre><code>class ViewHolder(private val binding: ItemSubjectDetailBinding): RecyclerView.ViewHolder(binding.root) {
  
      fun bind(day: Day) = with(binding) {
          tvSubject.text = day.subject
          tvInfo.text = &quot;${day.teacher}, ${day.type}&quot;
          tvTime.text = day.time
          tvAud.text = day.classroom
      }
  
      companion object {
          fun from(parent: ViewGroup): ViewHolder {
              val layoutInflater = LayoutInflater.from(parent.context)
              val binding = ItemSubjectDetailBinding.inflate(layoutInflater, parent, false)
              return ViewHolder(binding)
          }
      }
  }
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      return ViewHolder.from(parent)
  }
  
  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      with(holder) {
          bind(getItem(position))
      }
  }
  
  class ItemComparator: DiffUtil.ItemCallback&lt;Day&gt;() {
      override fun areItemsTheSame(oldItem: Day, newItem: Day): Boolean {
          return oldItem == newItem
      }
  
      override fun areContentsTheSame(oldItem: Day, newItem: Day): Boolean {
          return oldItem == newItem
      }
  }
  </code></pre>