'Android: Can't detect when ScrollView scrolled to the bottom

Here is my extracted code. I have tried some solution online but not working

  private val scrollView =  View.findViewById<NestedScrollView>(R.id.scroll)


 scrollView.setOnScrollChangeListener { _, _, Y, _, oY ->
        
        val scrollY = Y - oY
        if (scrollY > 1) {
          
        }else if (scrollY < -1) {
          
        }
    }


Solution 1:[1]

Try this code

scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, YAxis, _, _ ->
    if (view.getChildAt(0).bottom <= scrollView.height + YAxis) {
       //this detect when at the bottom
    }else{
      
    }
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1