androidandroid-recyclerviewandroid-pagedlistview

Pagedlistadapter return no item in recyclerView


I am trying to use PagedListAdapter to a custom RecyclerView, (link here).

In my ViewModel, when observing the data retrieved with Observer(adapter::submitList) no item is shown.

When debugging this line:

productViewModel.allProducts.observe(this, Observer(adapter::submitList))

I saw that a TiledPagedList object has my items / see picture -> Debugging Picture

In my repository class:

fun getProductsFromDb(): LiveData<PagedList<Product>> {
        return LivePagedListBuilder(productDao.getProducts(), 20).build()
    }

In my ViewModel class:

allProducts = repository.getProducts()

In my Activity class:

adapter = CardStackAdapter()
        productViewModel = ViewModelProviders.of(this).get(ProductViewModel::class.java)
        productViewModel.allProducts.observe(this, Observer(adapter::submitList))
productViewModel.allProducts.value?.dataSource?.invalidate()
//productViewModel .allProducts.observe(this, PagedList(adapter::submitList))

How can I apply correctly the items retrieved from my db to my recyclerView? (Apply what I see on TiledPagedList object)


Solution

  • I found the solution. My error was to override getItemCount() in my adapter class and to get the size of a list in parameter that was not used.