0

How can I display a message to the user after scrolling the recyclerview items and viewing the last item in the list?

The code below does not work

recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener(){
    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
        super.onScrolled(recyclerView, dx, dy)


        val count= recyclerView.layoutManager?.itemCount

        if (customerModels.size==count){
            Toast.makeText(applicationContext,"true",Toast.LENGTH_LONG).show()

        }

    }
})
mrp
  • 3
  • 2

1 Answers1

0

This is what I usually use when I want to check if the user is reached to the bottom of the recyclerView

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        LinearLayoutManager lm=LinearLayoutManager.class.cast(recyclerView.getLayoutManager());
        int items= lm.getItemCount();
        int last = lm.findLastVisibleItemPosition();

        boolean bottom= last+ 5 >= items;
        if (items> 0 && bottom) {
            //you have reached to the bottom of your recycler view
        }
    }
});
Elazar Halperin
  • 133
  • 1
  • 13