I am new to android first of all so think of any newbie mistakes first
I am trying to add a fling function in my code.
public class MainGamePanel ext
I tried the return value of onDown method to true, it didn't work. then i set ll_action_menu.setLongClickable(true);
it worked
For me I had to change the setLongClickable to true.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
view.setLongClickable(true); // <---- here
view.setOnTouchListener(getSwipeListener());
return view;
}
public OnTouchListener getSwipeListener() {
return new OnTouchListener() {
private GestureDetector gesture =
new GestureDetector(getActivity(),
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1,
MotionEvent e2,
float velocityX,
float velocityY) {
do some flinging here
return something
}
});
@Override
public boolean onTouch(View v, MotionEvent event) {
return gesture.onTouchEvent(event);
}
};
}
onDown
is called before the onFling
event.
If you return false in onDown
method, the motion event propagation will stop.
Try to change return false
in return true
at the end of onDown
method.
The return values are explained, somewhat obtusely, in the Input Events page of the Dev guide. (scroll down below the example code to see).
You need to set your view longclickable, like this:
yourView.setLongClickable(true);
Ideally we should not be.. GestureDetector works differently when associated with Activity Vs when it is associated with View. There is already an issue reported.. click here for more details.