1

I am building a fragment page which has a RecyclerView inside it.The RecyclerView gets the dates from a internet source(by using Retrofit).I am trying to call new data when the user scrolls to the end of recycler(in other words, some data is called when fragment is created and if the user scolls down new data will be called). Here is my code that I used for this purpose

      rvCategorie.viewTreeObserver.addOnScrollChangedListener {
            when {
layoutManager.findLastCompletelyVisibleItemPosition() == adapterCategorie.listSize() - 1 && (nextpageLink.toString().isNullOrEmpty() or !nextpageLink.toString().equals("null")) -> {
                    Caller.getcall(++categoriesCurrentPage)
                }
            }
        }

The problem is when use this code the "layoutManager.findLastCompletelyVisibleItemPosition()" method always returns the last item and calls the new data.Even though the item is not visible and also altough I do not scoll over the page it still calls new data

Note that : getcall() method is the method that calls the data and returns the datas (there is no problem with that).Also nextpageLink is updates itself when the call is done (it can be only a link(String) or null).

Is there any solution to my problem.Thank you.

Oğuzhan Aslan
  • 166
  • 2
  • 10

0 Answers0