使用 OnKeyListener
返回 true
和 false
有什么区别?
我看android官方文档[这里]( http://developer.android.com/reference/android/view/View.OnKeyListener.html "")!。
但是,我还是没有真正理解它。谁能更明确地向我解释一下 OnKeyListener
如何获得这两个返回?
最佳答案
如果您返回 false
,该事件将继续冒泡容器链
Returns True if the listener has consumed the event, false otherwise.
因为,如果你仔细想想,我们所做的必然是将 view
嵌套在彼此之中:
例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:onClick="layoutClicked" >
<Button
android:id="@+id/button1"
android:onClick="myButtonClicked" />
</LinearLayout>
想象一下单击按钮,如果您不返回 true
,layoutClicked
也会在 myButtonClicked
处理程序之后触发。
我觉得还有更多的解释in this article
关于android - 使用 OnKeyListener,return true 和 false 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27693018/