Detect Scroll Up & Scroll down in ListView

Link 1    Link2   Link3  Link4 Link5

(Working Link8 ) Link6    Link7    Link9


First, we'll need some class variables:
ListView listView;
ListView listView2;
View clickSource;
View touchSource;
int offset = 0;

Second, let's start with the OnTouchListener:
listView = (ListView) findViewById(;
listView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if(touchSource == null)
            touchSource = v;
        if(v == touchSource) {
            if(event.getAction() == MotionEvent.ACTION_UP) {
                clickSource = v;
                touchSource = null;
        return false;

Third, the OnItemClickListener:  (Optional)
listView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if(parent == clickSource) {
            // Do something with the ListView was clicked

Fourth, passing every touch event isn’t perfect because occasional discrepancies appear. The OnScrollListener is perfect for eliminating these:

listView.setOnScrollListener(new OnScrollListener() {
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        if(view == clickSource) 
            listView2.setSelectionFromTop(firstVisibleItem, view.getChildAt(0).getTop() + offset);

    public void onScrollStateChanged(AbsListView view, int scrollState) {}



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s