Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.42 KB | None | 0 0
  1.         recyclerView.layoutManager= LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL,false)
  2.  
  3.         recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener(){
  4.             override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
  5.                 val visibleItemCount = linearLayoutManager.childCount
  6.                 val pastVisibleItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition()
  7.                 val total = recyclerView.adapter!!.itemCount
  8.  
  9.                 if (!loading){
  10.                     if ((visibleItemCount +pastVisibleItem)>= total){
  11.                         page++
  12.                         history()
  13.                     }
  14.                 }
  15.                 super.onScrolled(recyclerView, dx, dy)
  16.             }
  17.  
  18.             override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
  19.                 super.onScrollStateChanged(recyclerView, newState)
  20.                 when(newState){
  21.                     RecyclerView.SCROLL_STATE_IDLE -> {
  22.                        toast(context, "no scroll")
  23.                     }
  24.                     RecyclerView.SCROLL_STATE_DRAGGING -> {
  25.                         toast(context, "scroll now")
  26.                     }
  27.                     RecyclerView.SCROLL_STATE_SETTLING -> {
  28.                         toast(context, "scroll settling")
  29.                     }
  30.                 }
  31.             }
  32.         })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement