Detect when RecyclerView reaches the bottom most position while scrolling

后端 未结 11 1879
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 19:56

I have this code for a RecyclerView.

    recyclerView = (RecyclerView)rootview.findViewById(R.id.fabric_recyclerView);
    recyclerView.setLayoutManager(layo         


        
11条回答
  •  我在风中等你
    2020-11-29 20:46

    This is my solution:

        val onScrollListener = object : RecyclerView.OnScrollListener() {
    
        override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
            directionDown = dy > 0
        }
    
        override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
            if (recyclerView.canScrollVertically(1).not()
                    && state != State.UPDATING
                    && newState == RecyclerView.SCROLL_STATE_IDLE
                    && directionDown) {
                   state = State.UPDATING
                // TODO do what you want  when you reach bottom, direction
                // is down and flag for non-duplicate execution
            }
        }
    }
    

提交回复
热议问题