title: how to remove previous result list immediately when updating recycler view?
body: <p>here is the short video of my problem:
  <a href="https://drive.google.com/file/d/108Tk9rmJtF3Ir7Nj9hheW2JkvlqXggcj/view" rel="nofollow noreferrer">https://drive.google.com/file/d/108Tk9rmJtF3Ir7Nj9hheW2JkvlqXggcj/view</a></p>
  
  <p>so, I have a vertical recycler view that can be refreshed when the tab layout is tapped.</p>
  
  <p>If I tap the first index of the tab, it will fetch some data from the server and populate the adapter and recycler view. but if I tap the second index, the data from server is actually empty.</p>
  
  <p>here is the problem...</p>
  
  <p>as you can see from the short video above. when I tap the second tab (from previously in the first tab), it still shows the list from the first tab appears for a second before eventually show an empty recycler view.</p>
  
  <p>I want to make after the loading the data from server, that previous result will not show, and it should immediately show the result as per the tab selected.</p>
  
  <p>I am using <code>ListAdapter</code> and using <code>submitList()</code> to update the data</p>
  
  <p>here is the adapter I use:</p>
  
  <pre><code>class GeneralEventRecyclerViewAdapter(val mContext: Context): ListAdapter&lt;Event, RecyclerView.ViewHolder&gt;(DIFF_CALLBACK) {
  
      lateinit var mOnEventKMListener : OnEventKMListener
  
      fun setOnItemClickListener(listener: OnEventKMListener) {
          mOnEventKMListener = listener
      }
  
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
          val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_general_event, parent, false)
          return GeneralEventViewHolder(itemView, mOnEventKMListener)
      }
  
      override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
  
          val currentEvent = getItem(position)
          val generalEventViewHolder = holder as GeneralEventViewHolder
  
          Glide.with(mContext).load(currentEvent.thumbnailDownloadPath)
              .apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3)))
              .into(generalEventViewHolder.blurThumbnailImageView)
  
          Glide.with(mContext).load(currentEvent.thumbnailDownloadPath).into(generalEventViewHolder.thumbnailImageView)
  
  
          generalEventViewHolder.eventNameTextView.text = currentEvent.title
          generalEventViewHolder.eventVenueTextView.text = currentEvent.venue
          generalEventViewHolder.eventDateTimeTextView.text = DateTimeService.changeDateToString("EEEE, d MMMM. HH:mm zzz",currentEvent.dateTimeStart)
  
      }
  
  
      companion object {
  
          private val DIFF_CALLBACK = object : DiffUtil.ItemCallback&lt;Event&gt;() {
              override fun areItemsTheSame(oldItem: Event, newItem: Event): Boolean {
                  return oldItem.eventID == newItem.eventID
              }
  
              override fun areContentsTheSame(oldItem: Event, newItem: Event): Boolean {
                  return oldItem == newItem
              }
  
  
          }
      }
  
  
  }
  </code></pre>
  
  <p>and here is the simplified my fragment class:</p>
  
  <pre><code>class SearchResultFragment : Fragment() {
  
      lateinit var titleTextView: TextView
      lateinit var progressBar : ProgressBar
      lateinit var fragmentView : View
      lateinit var tabLayout : TabLayout
      lateinit var recyclerView : RecyclerView
  
      lateinit var mContext : Context
      lateinit var mActivity : FragmentActivity
      lateinit var eventAdapter : GeneralEventRecyclerViewAdapter
  
      private var eventList = ArrayList&lt;Event&gt;()
      private var selectedEventType = EventType.kajianUmum
      private var selectedCity = City.defaultCityName
      private var selectedTime = EventTimeUserSelection.Weekend
      lateinit var userData : User
  
      private var startingDate = Date()
      private var endingDate = Date()
  
      override fun onAttach(context: Context) {
          super.onAttach(context)
  
          mContext = context
          activity?.let { mActivity = it }
  
      }
  
  
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          fragmentView = inflater.inflate(R.layout.fragment_search_result, container, false)
  
          setUpSafeArg()
          setUpViewsDeclaration()
          setUpListeners()
          updateUI()
          setHasOptionsMenu(true)
  
          initRecyclerView()
          searchEvents()
  
  
  
  
          return fragmentView
      }
  
  
  
      private fun setUpViewsDeclaration() {
          titleTextView = mActivity.findViewById(R.id.destination_label_text_view)
          progressBar = mActivity.progressBar_main_activity
          recyclerView = fragmentView.findViewById(R.id.recyclerView_search_result)
          tabLayout = fragmentView.findViewById(R.id.tabLayout_time_search_result)
  
      }
  
  
  
      private fun setUpListeners() {
  
          tabLayout.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
  
              override fun onTabSelected(tab: TabLayout.Tab?) {
  
                  selectedTime = when(tab?.position ?: 0) {
                      0 -&gt; EventTimeUserSelection.All
                      1 -&gt; EventTimeUserSelection.Today
                      2 -&gt; EventTimeUserSelection.Tomorrow
                      3 -&gt; EventTimeUserSelection.Weekend
                      4 -&gt; EventTimeUserSelection.ThisWeek
                      5 -&gt; EventTimeUserSelection.NextWeek
                      else -&gt; EventTimeUserSelection.All
                  }
  
                  searchEvents()
  
  
              }
  
              override fun onTabReselected(tab: TabLayout.Tab?) {
  
              }
  
              override fun onTabUnselected(tab: TabLayout.Tab?) {
  
              }
  
  
          })
  
      }
  
  
      private fun initRecyclerView() {
  
          eventAdapter = GeneralEventRecyclerViewAdapter(mContext)
          val layoutManager = LinearLayoutManager(mContext, RecyclerView.VERTICAL,false)
          recyclerView.adapter = eventAdapter
          recyclerView.layoutManager = layoutManager
  
  
          eventAdapter.setOnItemClickListener(object: OnEventKMListener {
  
              override fun eventKMClicked(position: Int) {
                  val selectedEvent = eventList[position]
                  val eventDetailDestination = SearchResultFragmentDirections.actionGlobalDestinationEventDetail(selectedEvent)
                  Navigation.findNavController(fragmentView).navigate(eventDetailDestination)
              }
  
          })
  
  
  
  
      }
  
      private fun searchEvents() {
  
          setStartingAndEndingDateForSearching()
          progressBar.visibility = View.VISIBLE
          recyclerView.visibility = View.GONE
  
  
          FirestoreKMClient.getFreeEvents(startingDate,endingDate,selectedCity,selectedEventType.getEventTypeInString(),10) { errorMessage, events -&gt;
  
  
              errorMessage?.let {
                  mActivity.toast(it)
              } ?: run {
  
                  val theEvents = events ?: ArrayList()
                  eventList = theEvents
                  eventAdapter.submitList(eventList)
              }
  
              progressBar.visibility = View.GONE
              recyclerView.visibility = View.VISIBLE
  
  
          }
  
  
      }
  
  
  }
  </code></pre>
  
  <p>Java is ok</p>