gpt4 book ai didi

java - 在 setOnLongClickListner 中返回 true

转载 作者:行者123 更新时间:2023-12-01 21:30:42 24 4
gpt4 key购买 nike

任何人都可以告诉我为什么必须在 setOnLongClickListner(); 的末尾返回 true;当我尝试将返回类型从 Boolean 更改为 void 时,它会给我一个错误。

最佳答案

Can any one please tell me why it is necessary to return true in the end of setOnLongClickListner();

不一定要返回true,需要返回boolean,所以可以是false。

来自文档:

Returns boolean true if the callback consumed the long click, false otherwise.

这意味着,如果返回 true,事件就会停止传播。否则,该事件将继续传播并调用其他相关事件。

例如,如果您返回 false,您的 OnLongClick 事件将被触发。完成后,您的 onClickListener 将被触发。如果返回 true,事件将在 OnLongClickListener 中停止。

when I try to change the return type from Boolean to void then it gives me an error

您正在实现一个接口(interface)。该方法已定义,但尚未实现。你无法改变它。有关此的更多信息:

https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

关于java - 在 setOnLongClickListner 中返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37481679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com