Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// ...(略)
mList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
var mShouldReload = false
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
val firstVisibleItem = layoutManager.findFirstVisibleItemPosition()
val visibleItemCount = layoutManager.childCount
val totalItemCount: Int = layoutManager.itemCount
mShouldReload = firstVisibleItem + visibleItemCount == totalItemCount && dy > 0
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE && mShouldReload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment