Naruto
Naruto

Reputation: 245

how to get smooth scroll in listview

I am auto scrolling listview which has 1000 items in it..by running a thread which runs smoothscroll , i am letting the user to swipe the listview by stopping the thread until the list view scroll and again starting the thread .. Every thing is fine ,but the problem is there is delay between the autoscroll to start after the swipe .. How to have smooth transition from swipe scroll to auto scroll.

protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
                --------
                --------
                ThreadAutoScroll();
}

private void autoScroll() {


            if(!touched)
            {
                listView.smoothScrollBy(1,30);
            }

    }

public onTouch(Moition event)
{
switch(event.getAction())
        {
        case MotionEvent.ACTION_DOWN:
            touched = true ;
            break;
            }
}

public void onScrollStateChanged(AbsListView view, int scrollState) {
        // TODO Auto-generated method stub

        if(touched && scrollState =0) 
               {
                 touched = true;
               }
    }

Upvotes: 3

Views: 5323

Answers (2)

Amit Jayaswal
Amit Jayaswal

Reputation: 1723

Try this code simply in your code. I hope it will help.

 GestureDetector mGD = new GestureDetector(getBaseContext(),
        new SimpleOnGestureListener() {

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// beware, it can scroll to infinity
scrollBy((int)distanceX, (int)distanceY);
return true;
}

private void scrollBy(int distanceX, int distanceY) {
distanceX =10;
distanceY =10;
}

@Override
public boolean onDown(MotionEvent e) {
if(!mScroller.isFinished() ) { // is flinging
mScroller.forceFinished(true); // to stop flinging on touch
}
return true; // else won't work
}
});

@Override
public boolean onTouchEvent(MotionEvent event) {
return mGD.onTouchEvent(event);
}

Upvotes: 0

Avadhani Y
Avadhani Y

Reputation: 7646

Set the Smooth Scollbars for the listview as below:

listView.setSmoothScrollbarEnabled(true);

Upvotes: 1

Related Questions