Reputation: 10353
I have a list view that contains about 30 items. When I scroll it down it just goes to the very bottom of the list and does not stop when the user touches the list.
Is there a method to stop the scrolling when the list view is touched and at the same time user should be able to navigate using onItemClick(already handled)..
Thank you!
Upvotes: 2
Views: 5523
Reputation: 287
Use smoothScrollBy
.
@Override
public boolean onTouchEvent(MotionEvent ev)
{
switch (ev.getAction())
{
case MotionEvent.ACTION_UP:
this.smoothScrollBy(0, 0);
break;
}
return super.onTouchEvent(ev);
}
Upvotes: 6
Reputation: 10353
By referring to Nitin Gupta's answer, I came up with my own:
public class OnTouchListenr implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
businessResultListView.smoothScrollBy(0, 0);
return true;
}
return false;
}
}
Then I set the OnTouchListener on the list view like this:
businessResultListView.setOnTouchListener(new OnTouchListenr());
Upvotes: 0
Reputation: 1023
Override dispatchTouchEvent in your Listview
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
if(ev.getAction()==MotionEvent.ACTION_MOVE){
return true;
}return super.dispatchTouchEvent(ev);
}
Upvotes: 0