[英]Android - Why does onItemLongClick(…) return a boolean?
来自Java背景我习惯于处理动作虽然我不确定为什么该方法需要返回布尔值并且不完全理解网站上给出的解释:如果回调消耗了长按,则为true,false除此以外。
As you may know, the View
hierarchy in Android is represented by a tree. 您可能知道,Android中的
View
层次结构由树表示。 When you return true
from the onItemLongClick()
- it means that the View
that currently received the event is the true event receiver and the event should not be propagated to the other Views
in the tree; 当您从
onItemLongClick()
返回true
- 这意味着当前接收到该事件的View
是真正的事件接收者,并且该事件不应传播到树中的其他Views
; when you return false
- you let the event be passed to the other Views
that may consume it. 当您返回
false
- 您将事件传递给可能使用它的其他Views
。 Hope this helps. 希望这可以帮助。
I will further clarify this for you, by way of an example. 我将通过一个例子进一步澄清这一点。
@Override
public boolean onLongClick(View view) {
//Do all you stuff here
return true; // or you can return false;
}
So, after your onLongClick() has fired, if you don't want the regular onClick() to fire, then just return true from the onLongClick() event. 因此,在你的onLongClick()被触发之后,如果你不希望触发常规onClick() ,那么只需从onLongClick()事件返回true 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.