1

In my application trying to listen the listView scroll movement whether it is up or down.

contactsList.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

            view.setOnTouchListener(new View.OnTouchListener() {

                private float mInitialX;
                private float mInitialY;
                @Override
                public boolean onTouch(View v, MotionEvent event) {

                    switch (event.getAction())
                    {
                        case MotionEvent.ACTION_DOWN:
                            mInitialX = event.getX();
                            mInitialY = event.getY();
                            return true;
                        case MotionEvent.ACTION_MOVE:
                            final float x = event.getX();
                            final float y = event.getY();
                            final float yDiff = y - mInitialY;
                            if (yDiff > 0.0) {
                                Log.e("Tag ","Scroll down");

                                break;

                            } else if (yDiff < 0.0) {
                                Log.e("Tag ","Scroll up");

                                break;

                            }
                            break;
                    }
                    return false;
                }
            });
        }

I've tried this code. But it is not working perfectly.

When I'm scrolling up , it shows in the log "Scroll Up" at first time, then it shows "Scroll Down".

Can anyone tell me why it behaves like this.

Thanks in advance :)

abbath
  • 2,444
  • 4
  • 28
  • 40
  • What would you like to track exactly? whether the user is moving his finger up or down, or the list' state, whether it's moving up or down? With the current solution you're tracking the finger touch movement of the user. – abbath Oct 26 '15 at 13:19
  • I want to track weather the user is moving his finger up or down –  Oct 26 '15 at 13:20

1 Answers1

0

Try this solution, your problem seems similar, maybe tracking the direction of the scroll is enough for what you need.

Community
  • 1
  • 1
abbath
  • 2,444
  • 4
  • 28
  • 40