title: How to show empty view while using Android Paging 3 library
body: <p>I am using Paging 3 lib. and i am able to check if refresh state is &quot;Loading&quot; or &quot;Error&quot; but i am not sure how to check &quot;empty&quot; state.I am able to add following condition but i am not sure if its proper condition</p>
  <pre><code>adapter.loadStateFlow.collectLatest { loadStates -&gt;
                  viewBinding.sflLoadingView.setVisibility(loadStates.refresh is LoadState.Loading)
                  viewBinding.llErrorView.setVisibility(loadStates.refresh is LoadState.Error)
                  viewBinding.button.setOnClickListener { pagingAdapter.refresh() }
  
                  if(loadStates.refresh is LoadState.NotLoading &amp;&amp; (viewBinding.recyclerView.adapter as ConcatAdapter).itemCount == 0){
                      viewBinding.llEmptyView.setVisibility(true)
                  }else{
                      viewBinding.llEmptyView.setVisibility(false)
                  }
              } 
  </code></pre>
  <p>Also I am running into other problem
  I have implemented search functionality and until more than 2 characters are entered i am using same paging source like following but the above loadstate callback is executed only once.So thats why i am not able to hide empty view if search query is cleared.I am doing so to save api call from front end.</p>
  <pre><code>private val originalList : LiveData&lt;PagingData&lt;ModelResponse&gt;&gt; = Transformations.switchMap(liveData){
          repository.fetchSearchResults(&quot;&quot;).cachedIn(viewModelScope)
      }
  
      val list : LiveData&lt;LiveData&lt;PagingData&lt;ModelResponse&gt;&gt;&gt; = Transformations.switchMap{ query -&gt;
          if(query != null) {
              if (query.length &gt;= 2)
                  repository.fetchSearchResults(query)
              else
                  originalList
          }else
              liveData { emptyList&lt;ModelResponse&gt;() }
      } 
  </code></pre>