Question

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?

thank you.

Was it helpful?

Solution

As the link you posted says,

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

and if you read what the params mean

Parameters

v The view whose state has changed.

hasFocus The new focus state of v.

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).

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.

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 Listeners

Java 6 Docs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top