How can I identify that RecyclerView's last item is visible on screen?

前端 未结 5 1885
自闭症患者
自闭症患者 2021-01-31 19:18

I have one RecyclerView and I added list of data into the RecyclerView. I wanted to add more data in list, when last RecyclerView item is

5条回答
  •  梦毁少年i
    2021-01-31 19:50

    See also Android - Detect when the last item in a RecyclerView is visible.

    private fun isLastItemVisible(): Boolean {
        val layoutManager = recycler_view.layoutManager
        val position = layoutManager.findLastCompletelyVisibleItemPosition()
        return position >= adapter.itemCount - 1
    }
    

提交回复
热议问题