Reputation: 4958
I want to disable the fling gesture of a scrollview and it does not seem to be working.. I thought it would be as easy as creating a basic class that extends scrollview and @Overriding
the onFling
method. but eclipse is giving me an error to remove the @Override:
any ideas how to disable the fling
public class ScrollViewNoFling extends ScrollView {
/**
* @param context
* @param attrs
* @param defStyle
*/
public ScrollViewNoFling(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public ScrollViewNoFling(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public ScrollViewNoFling(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
return false;
}
}
Upvotes: 6
Views: 8016
Reputation: 543
I solved same problem with Override fling method. If you override fling method on your ScrollViewNoFling class and not call super.fling on this method, you gonna have not-fling-handled scrollView.
@Override
public void fling (int velocityY)
{
/*Scroll view is no longer gonna handle scroll velocity.
* super.fling(velocityY);
*/
}
Upvotes: 17
Reputation: 67209
In addition to using fling()
instead of onFling()
, you need to pay attention to your return values.
As per the documentation for onFling():
Returns
true if the event is consumed, else false
If you want to catch the event and do nothing, return true. Otherwise, the event will be passed on to some other method/class to attempt to handle it.
Upvotes: 0
Reputation: 7964
I think it should be fling and not onFling. Please refer to the official documentation
Upvotes: 0