Android Ontouchlistener Stops Receiving Events When Finger Is Moved Up
I have a custom view with the following OnTouchListener assigned to it in my activity: private OnTouchListener MyOnTouchListener = new OnTouchListener() { public boolean onTouc
Solution 1:
Well this might be old, but it still comes up in the search results. It's possible to prevent the ScrollView from intercepting the touch events by doing this:
private OnTouchListener MyOnTouchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN){
//our touch handling began, request the scrollview not to interact
scrollView.requestDisallowInterceptTouchEvent(true);
System.out.println("Down");
System.out.println("x" + event.getX() + ", y: " + event.getY());
}elseif(event.getAction()==MotionEvent.ACTION_MOVE){
System.out.println("Move");
System.out.println("x" + event.getX() + ", y: " + event.getY());
}elseif(event.getAction()==MotionEvent.ACTION_UP){
//re-enable it after we're done (finger goes up)
scrollView.requestDisallowInterceptTouchEvent(true);
System.out.println("up");
System.out.println("x" + event.getX() + ", y: " + event.getY());
}
returntrue;
}
};
Solution 2:
It turns out the issue is that the view is contained in a ScrollView. Removing the ScrollView fixes the problem.
Solution 3:
you have to specify the event into the onTouch like down, move or up for that you have to do like this way.
private OnTouchListener MyOnTouchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN){
System.out.println("Down");
System.out.println("x" + event.getX() + ", y: " + event.getY());
}elseif(event.getAction()==MotionEvent.ACTION_MOVE){
System.out.println("Move");
System.out.println("x" + event.getX() + ", y: " + event.getY());
}elseif(event.getAction()==MotionEvent.ACTION_UP){
System.out.println("up");
System.out.println("x" + event.getX() + ", y: " + event.getY());
}
returntrue;
}
};
Post a Comment for "Android Ontouchlistener Stops Receiving Events When Finger Is Moved Up"