Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

878
Vistas
Check if the list is empty on the first request in Paging 3.0

I'm trying to check if the first request came with the empty object, to display a layout indicating that it has no item.

My solution was to create an exception of my own. I would like to know if there is another better way. Because I looked in the documentation and found nothing.

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Item> {
    return try {
        val position = params.key ?: FIRST_PAGE_INDEX
        val response = api.getItem(position, params.loadSize, searchKey)
        val nextKey = response?.next
        val itemList = response?.itemList ?: emptyList()

        if (itemList.isNotEmpty()) {
            LoadResult.Page(
                data = itemList,
                prevKey = null,
                nextKey = if (nextKey == LAST_PAGE_INDEX) null else nextKey
            )
        } else {
            LoadResult.Error(EmptyListException())
        }

    } catch (exception: IOException) {
        LoadResult.Error(exception)
    } catch (exception: HttpException) {
        LoadResult.Error(exception)
    }
}
over 4 years ago · Hanz Gallego
1 Respuestas
Responde la pregunta

0

To show EmptyView you can look loadState.append which represents the load state for loading data at the end of the list and can confirm if there is no more data to load using endOfPaginationReached and after that can check itemCout of PagingDataAdapter. ` .

eg:  adapter.addLoadStateListener { loadState ->

            if ( loadState.append.endOfPaginationReached )
            {
               if ( adapter.itemCount < 1)
                    /// show empty view
               else 
                   ///  hide empty view
            }
           }
over 4 years ago · Hanz Gallego Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda