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?
When
keywordchanges, you have to callitemUseCase.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.