I load the RecyclerView and the ScrollListener inside a function
This is the code for setting the ScrollListener inside of it (I removed everything non necessary for the question):
recyclerViewMemes.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val firstPosition = layoutManager.findFirstVisibleItemPosition()
val lastPosition = layoutManager.findLastVisibleItemPosition()
for (i in firstPosition..lastPosition) {
if(adapterMemes.memes[i].pic.contains("_vid_")){ // ERROR HERE
Log.d(tagg, "bla")
}
}
}
})
When I try to reset the RecyclerView by calling the function again I get ArrayIndexOutOfBoundsException on the line I commented with ERROR HERE. Which means the RecyclerView still gets triggered while resetting everything.
So how can I prevent this? Like removing / resetting the ScrollListener?