4

I want to detect the end of scroll event of a scrollView. first,i implement the OnCrollChange method and i try to listen some values if they can help me to know the end of scroll. Thank to help me.

 scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener(){
            @Override
            public void onScrollChange(View view, int i, int i1, int i2, int i3){
                Toast.makeText(getApplicationContext(),"in SCroll ------->"+i+" "+i1+" "+i2+" "+i3,Toast.LENGTH_SHORT).show();
                shadowView.setBackgroundResource(R.drawable.shadow);
                if ((i3==0)){
                    Toast.makeText(getApplicationContext()," equality ----------------------> ",Toast.LENGTH_SHORT).show();
                    shadowView.setBackgroundResource(R.drawable.trans);
                }
                else {
                   // Toast.makeText(getApplicationContext()," NO ----------------------> ",Toast.LENGTH_SHORT).show();
                }
            }

        });
Boris
  • 99
  • 1
  • 13

3 Answers3

3

This will help

scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
        if (scrollView != null) {
            if (scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY())) {
                //scroll view is at bottom
            } else {
                //scroll view is not at bottom
            }
        }
    }
});
Viswanath Kumar Sandu
  • 2,230
  • 2
  • 17
  • 34
1

Modify your onScrollChanged method as below

       @Override
        public void onScrollChanged(View view, int i, int i1, int i2, int i3){
            View view = (View) getChildAt(getChildCount()-1);
            int delta = (view.getBottom()-(getHeight()+getScrollY()));
            if(delta == 0){
                // You have reached bottom of the scroll view
            }
        }
Krishna Sharma
  • 2,828
  • 1
  • 12
  • 23
0

Thank to all of you. after some testes;i see that the values int i, int i1, int i2 take the same value egual to 0 at the real time so it solve my problem. I will not use your suggestions now but i learn some important notion from them only by reading.

Boris
  • 99
  • 1
  • 13