Android - 为什么onItemLongClick(...)返回一个布尔值? [英] Android - Why does onItemLongClick(...) return a boolean?
问题描述
来自Java背景我习惯于处理操作虽然我不确定为什么该方法需要返回布尔值并且不完全理解网站上给出的解释:如果回调消耗了长的话,则为true点击,否则返回false。
Coming from a Java background I am used to dealing with actions though I'm not really sure why the method requires a boolean is returned and don't fully understand the explanation given on the site: true if the callback consumed the long click, false otherwise.
推荐答案
如您所知,查看
Android中的层次结构由树表示。当您从 onItemLongClick()
返回 true
时 - 表示查看$当前收到事件的c $ c>是真正的事件接收者,该事件不应传播到树中的其他
Views
;当你返回 false
时 - 你将事件传递给可能消耗它的其他 Views
。希望这会有所帮助。
As you may know, the View
hierarchy in Android is represented by a tree. 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; when you return false
- you let the event be passed to the other Views
that may consume it. Hope this helps.
这篇关于Android - 为什么onItemLongClick(...)返回一个布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!