什么是OnFocusChange监听器在Android中?监听器、OnFocusChange、Android

2023-09-07 03:00:59 作者:梦想起航我起床

我现在正在学习的Andr​​oid和一个运动是需要我去执行 onFocusChangeListener 的EditText 感动。但是,我能够找到的有关 onFocusChangeListener 的信息非常少。在Android开发网站这里有非常非常的简要信息。我已经做了搜索,但我才能够找到的有关开发商已经遇到过极少数的信息被赋予了特定的问题一些帖子。谁能给我在这里介绍或谈论更多的细节什么联系呢?

I am now learning Android and one exercise is requiring me to implement onFocusChangeListener when a EditText is touched. However, I was able to find very little information about onFocusChangeListener. On the Android Development website here there is very very brief information. I have done search but I was only able to find some posts about the specific problems developers have encountered where very few information was given. Can anyone give me an introduction here or any link that talks about that more in detail?

感谢您。

推荐答案

当你发布的链接说,

回调接口定义,当一个视图的聚焦状态改为被调用。

Interface definition for a callback to be invoked when the focus state of a view changed.

如果你读一下 PARAMS 的意思是

参数

v,其状态已经改变。视图

v The view whose state has changed.

hasFocus v的新焦点状态。

hasFocus The new focus state of v.

所以,如果你设置这个在的EditText 或多个的EditText S,您可以使用 v 参数知道哪些查看的焦点已经改变。您还可以使用 hasFocus 来确定它是否也只是获得焦点(则返回true ),或者如果它刚刚失去焦点因为它给了别人(返回false )。

So if you set this on a EditText, or multiple EditTexts, you can use the v param to know which Views focus has changed. And you can use hasFocus to determine if it did just gain focus (returns true) or if it has just lost focus because it was given to someone else (returns false).

所以,也许你想开始有些动画查看当焦点在它或其他改变查看,您可以设置此监听器和被调用时,你可以启动动画如果 hasFocus 收益真正

So, maybe you want to start some animation on a View when focus is changed on it or another View, you set this listener and when it is invoked you can start the animation if hasFocus returns true.

如果你仍然感到困惑,那么请解释的什么的你不明白它。

If you are still confused then please explain what you don't understand about it.

至于不给多的信息的文档,他们认为阅读这时候你有什么听众和方法做,有关如何使用参数,它需要和回报。该文档还期望的Java有一定的了解。因此,对于你的另一个问题,我知道如果我不明白的东西,因为我不认为做Android的文档已经彻底覆盖,然后我会检查Java文档。

As for the docs not giving much information, they assume that when reading this you have adequate information of what listeners and methods do and about how to use parameters that it takes and returns. The docs also expect a certain knowledge of Java. So for your other question, I know if I don't understand something because I don't think the Android docs have covered it thoroughly, then I would check the Java docs.

的Java侦听

Java 6的文档