简体   繁体   English

为什么onLongPress()不像其他所有SimpleOnGestureListener一样返回布尔值?

[英]Why does onLongPress() not return a boolean like all other SimpleOnGestureListener?

As the title states. 如标题所述。 The fact that I can't consume the event is causing a click event to occur immediately afterwards. 我无法使用该事件的事实导致click事件随后立即发生。 Now I am manually keeping track of whether or not a longpress has occurred when handling a potential click. 现在,我手动跟踪在处理潜在点击时是否发生了长按。

Am I missing something here? 我在这里想念什么吗? I mean, I can't even get around this trying to implement the OnGestureListener interface because it expects a void for onLongPress() . 我的意思是,我什至无法解决尝试实现OnGestureListener接口的问题,因为它期望onLongPress()无效。 What are my options? 我有什么选择?

I think the onLongPress don't like the onDown these, the return value of the onLongPress is not used to check something, but the return value of onDown is useful to the system, it will help the system to recognitive another events. 我认为onLongPress不喜欢onDown这些,onLongPress的返回值不用于检查某些东西,但是onDown的返回值对系统很有用,它将帮助系统识别其他事件。 From the android source code: 从android源代码:

   mStillDown = true;
   mInLongPress = false;
   if (mIsLongpressEnabled) {
      mHandler.removeMessages(LONG_PRESS);
      mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime() +      TAP_TIMEOUT + LONGPRESS_TIMEOUT);
    }
       mHandler.sendEmptyMessageAtTime(SHOW_PRESS, mCurrentDownEvent.getDownTime() + TAP_TIMEOUT);
      handled |= mListener.onDown(ev);

the onLongPress and ShowPress just tell these situations happend. onLongPress和ShowPress只是告诉您发生了这些情况。 The return value is not useful for system. 返回值对系统没有用。

And if you want to implement your design, you can use the varable to check whether the LongPress happened. 如果要实现设计,则可以使用该变量检查LongPress是否发生。 Hope this can help you. 希望这可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android - 为什么onItemLongClick(...)返回一个布尔值? - Android - Why does onItemLongClick(…) return a boolean? 为什么在 List 接口中只有 add(int index, E element) 返回 void 而所有其他 add 方法都返回 boolean - Why in List interface only add(int index, E element) returns void wheras all other add methods return boolean 为什么Java ArrayList类返回一个布尔值来添加? - Why does the Java ArrayList class return a boolean for add? 为什么这个布尔方法使用错误的返回路径? - Why does this boolean method use the wrong return path? 为什么“自定义 Enum 构造函数”会返回所有其他 Enum 类型的信息? - Why does a “customised Enum constructor” return the info of all the other Enum type? 为什么方法Queue#add()有布尔返回值? - Why does method Queue#add() has boolean return value? 为什么字符串返回布尔可测试值? - Why does a string return a boolean-testable value? 为什么默认的布尔值会影响我的测试结果 - Why does the default Boolean return value influence my tests outcome 为什么java.util.Collection.remove()返回一个布尔值? - Why does java.util.Collection.remove() return a boolean? 为什么我的 Validare Zip Code(boolean) 程序返回 false? - Why does my Validare Zip Code(boolean) program return false?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM