大佬教程收集整理的这篇文章主要介绍了长按Android,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是与此问题相关的代码
final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpLeonGestureListener() { public void onLongPress(MotionEvent E) { Log.e("dbg_msg","onLongPress"); } }); public Boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); };
当我将此代码放在继承自Activity的类中时,它可以工作.
那么为什么它不能在自定义视图中工作?
public static int LONG_PRESS_TIME = 500; // Time in miliseconds final Handler _handler = new Handler(); Runnable _longPressed = new Runnable() { public void run() { Log.i("info","LongPress"); } }; @Override public Boolean onTouchEvent(MotionEvent event) { switch(event.getAction()){ case MotionEvent.ACTION_DOWN: _handler.postDelayed(_longPressed,LONG_PRESS_TIME); break; case MotionEvent.ACTION_MOVE: _handler.removeCallBACks(_longPressed); break; case MotionEvent.ACTION_UP: _handler.removeCallBACks(_longPressed); break; } return true; }
以上是大佬教程为你收集整理的长按Android全部内容,希望文章能够帮你解决长按Android所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。