2

whit this below action i can check scrolling list view down is finish. now i want to check list view scrolling to up and finish. how to get this event?

@Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        if (prevVisibleItem != firstVisibleItem) {
            if (prevVisibleItem < firstVisibleItem)
                Log.e(getClass().toString(), "DOWN");
            else
                Log.e(getClass().toString(), "UP");

            prevVisibleItem = firstVisibleItem;
            /*
            * CHECK SCROLLING BUTTOM FINISH
            */

            if((firstVisibleItem + visibleItemCount) ==  totalItemCount)
            {
                Log.i("Info", "Scroll Bottom FINISH" );
            }

            /*
            * CHECK SCROLLING UP FINISH
            */
        }
    }
DolDurma
  • 15,753
  • 51
  • 198
  • 377
  • That might be helpful...[CLICKHERE](http://stackoverflow.com/questions/6358428/implementation-of-onscrolllistener-to-detect-the-end-of-scrolling-in-a-listview) – TeachMeJava Aug 28 '14 at 08:00
  • @TeachMeJava thats link is `end of scrolling in a ListView` – DolDurma Aug 28 '14 at 08:14

3 Answers3

3
if(firstVisibleItem == 0 && !isFirstTime){
 //it is top of the list
}

define a variable in your class isFirstTime and initialize it to true. when the user scroll the list check

if (firstVisibleItem  != 0 )
{
    isFirstTime =false;
}

that means the user scrolls the list and the first element is disappear so if once again

firstVisibleItem  == 0

means the list scrolls up and finishs.

mmlooloo
  • 18,937
  • 5
  • 45
  • 64
0

use OnSwipeTouchListener.java:

import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class OnSwipeTouchListener implements OnTouchListener {

    private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());

    public boolean onTouch(final View view, final MotionEvent motionEvent) {

        super.onTouch(view, motionEvent);
        return gestureDetector.onTouchEvent(motionEvent);

    }

    private final class GestureListener extends SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 100;
        private static final int SWIPE_VELOCITY_THRESHOLD = 100;

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            boolean result = false;
            try {
                float diffY = e2.getY() - e1.getY();
                float diffX = e2.getX() - e1.getX();
                if (Math.abs(diffX) > Math.abs(diffY)) {
                    if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffX > 0) {
                            onSwipeRight();
                        } else {
                            onSwipeLeft();
                        }
                    }
                } else {
                    if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffY > 0) {
                            onSwipeBottom();
                        } else {
                            onSwipeTop();
                        }
                    }
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return result;
        }
    }
    public void onSwipeRight() {}
    public void onSwipeLeft() {}
    public void onSwipeTop() {}
    public void onSwipeBottom() {}
}

USAGE:

imageView.setOnTouchListener(new OnSwipeTouchListener() {

    public void onSwipeTop() {
        Toast.makeText(MyActivity.this, "top", Toast.LENGTH_SHORT).show();
    }
    public void onSwipeRight() {
        Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show();
    }
    public void onSwipeLeft() {
        Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show();
    }
    public void onSwipeBottom() {
        Toast.makeText(MyActivity.this, "bottom", Toast.LENGTH_SHORT).show();
    }

});
raj
  • 2,088
  • 14
  • 23
0

That might be helpful.I searched your problem on stackoverflow,and I think this answer is exactly your question's answer. Scroll finish detect. Click Here for Full Code Answer

private void isScrollCompleted() {
    if (this.currentVisibleItemCount > 0 && this.currentScrollState == SCROLL_STATE_IDLE) {
        /*** In this way I detect if there's been a scroll which has completed ***/
        /*** do the work! ***/
    }
}
Community
  • 1
  • 1
TeachMeJava
  • 640
  • 1
  • 13
  • 35
  • @TechMeJava . how to resolve `currentVisibleItemCount` and `currentScrollState`? my Class extends `ListFragment` – DolDurma Aug 28 '14 at 08:10