Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- recyclerView.layoutManager= LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL,false)
- recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener(){
- override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
- val visibleItemCount = linearLayoutManager.childCount
- val pastVisibleItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition()
- val total = recyclerView.adapter!!.itemCount
- if (!loading){
- if ((visibleItemCount +pastVisibleItem)>= total){
- page++
- history()
- }
- }
- super.onScrolled(recyclerView, dx, dy)
- }
- override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
- super.onScrollStateChanged(recyclerView, newState)
- when(newState){
- RecyclerView.SCROLL_STATE_IDLE -> {
- toast(context, "no scroll")
- }
- RecyclerView.SCROLL_STATE_DRAGGING -> {
- toast(context, "scroll now")
- }
- RecyclerView.SCROLL_STATE_SETTLING -> {
- toast(context, "scroll settling")
- }
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement