Android TextView NullPointerException with onTouchListener and onClickListener on 4.0

青春壹個敷衍的年華 提交于 2019-12-05 15:31:14

My friend, try to return true when you get events you want to handle from _gestureDetector:

 public boolean onTouch(View v, MotionEvent event) {
     if (_gestureDetector.onTouchEvent(event)) {
         return true;
     }
     return false;
 }

Otherwise, return false.

I had a look at the Android source (4.0.1 r1) for GestureDetector: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/view/GestureDetector.java?av=f

Line 587 doesn't look like it could be the source of the problem, since mVelocityTracker is always initialized by that point. Any idea which build of 4.0 you have?

This may be a bug in 4.0, and I would file a bug report to them about it here:

http://code.google.com/p/android/issues/list

In the mean time, is it possible for you do move the code in your OnClickListener into the OnSingleTapConfirmed method of the SimpleGestureListener? That way, it should still do the right thing as if your click listener is commented out, but you get the same behavior.

http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html#onSingleTapConfirmed(android.view.MotionEvent)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!