PagedList
is used for Android\'s cool paging library. To make the question as minimal as possible :
If i have a list of strings like
This is how I solve my problem, this might help.
val items = List- .... //this can be equal to your mutable list
val config = PagedList.Config.Builder()
.setPageSize(items.size)
.setEnablePlaceholders(false)
.setInitialLoadSizeHint(items.size)
.build()
val pagedList = PagedList.Builder(ListDataSource(items),config)
.setNotifyExecutor (UiThreadExecutor ())
.setFetchExecutor (AsyncTask.THREAD_POOL_EXECUTOR)
.build ()
class UiThreadExecutor: Executor {
private val handler = Handler (Looper.getMainLooper ())
override fun execute (command: Runnable) {
handler.post (command)
}
}
class ListDataSource (private val items: List
- ): PageKeyedDataSource
() {
override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback) {
callback.onResult (items, 0, items.size)
}
override fun loadAfter(params: LoadParams, callback: LoadCallback) {
}
override fun loadBefore(params: LoadParams, callback: LoadCallback) {
}
}
Other Resources: android - how to convert list to pagedlist