Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

877
Views
Compruebe si la lista está vacía en la primera solicitud en Paging 3.0

Estoy tratando de verificar si la primera solicitud vino con el objeto vacío, para mostrar un diseño que indica que no tiene ningún elemento.

Mi solución fue crear una excepción propia. Me gustaría saber si hay otra manera mejor. Porque busqué en la documentación y no encontré nada.

 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 answers
Answer question

0

Para mostrar EmptyView, puede mirar loadState.append , que representa el estado de carga para cargar datos al final de la lista y puede confirmar si no hay más datos para cargar usando endOfPaginationReached y luego puede verificar itemCout de 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!