0

In my project using PagedListAdapter for pagination and the app also able to search by keyword.

DAO.kt

@Query("SELECT * FROM Item WHERE name LIKE :keyword")
fun getItems(keyword: String): DataSource.Factory<Int, ItemEntity>

Create

lateinit var itemLivePagedList: LiveData<PagedList<Item>>

.
.
.

val dataSourceFactory = itemUseCase.getItems(keyword)
val boundaryCallback = MyBoundaryCallback(itemUseCase, compositeDisposable, PAGE_SIZE)
itemLivePagedList = LivePagedListBuilder(dataSourceFactory, pagedListConfig)
            .setBoundaryCallback(boundaryCallback)
            .build()

How can I update the list when keyword changed?

Muntasir Aonik
  • 1,288
  • 1
  • 7
  • 20
a-rohim
  • 417
  • 1
  • 4
  • 13

1 Answers1

1

When keyword changes, you have to call itemUseCase.getItems(keyword) again.

Look at this project. it has been written in Java but it shows how to implement a search scenario with PagingLibrary.

For more details see this answer.

Mir Milad Hosseiny
  • 2,429
  • 13
  • 18