Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 27
Registered: ‎07-27-2011
My Device: curve
My Carrier: vodafone

setFocus() is not calling onFocus() !!

hello,

 

here  when i set *.setFocus() for a field , it is not calling the onFocus().

 

please help it. why is it now giving a callback !!      whereas in the other places for other fields its working well.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: setFocus() is not calling onFocus() !!

setFocus is not supposed "call" onFocus. Rather, it generates series of events, one of which, in case the focus went to a different field, causes that new field's onFocus to be called. If the newly focused field belongs to a different Manager than the previous one, that Manager's onFocus will also be called.

 

In addition, I've witnessed an OS bug where onUnfocus would not be invoked even when it was supposed to. I've never seen onFocus not work, but can imagine it being buggy as well. I've long since switched to FocusChangeListener in my projects and never looked back.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Developer
Posts: 27
Registered: ‎07-27-2011
My Device: curve
My Carrier: vodafone

Re: setFocus() is not calling onFocus() !!

so.. in between the series of events its not calling the onFocus of that field, as setFocus causes to attract the focus .. so i should call the onFocus too, of the field that have just gained the focus  !! ryt !! so its not doing that !! ... i am doing it for a custom field !

Developer
Posts: 94
Registered: ‎07-08-2011
My Device: Many

Re: setFocus() is not calling onFocus() !!

I dont remember wher but in my first days learning bb dev in the examples or tutorials there where some flags in the code like hasFocus or isActive.

Maybe is related to what arkadyz is saying.


Feel free to press the like button on the right side to thank the user that helped you.
Please mark posts as solved if you found a solution.

Juanma 

@juanmab

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: setFocus() is not calling onFocus() !!

 


jai1989 wrote:

so.. in between the series of events its not calling the onFocus of that field, as setFocus causes to attract the focus .. so i should call the onFocus too, of the field that have just gained the focus  !! ryt !! so its not doing that !! ... i am doing it for a custom field !


No, you never explicitly call a field's onFocus (aside from super.onFocus from your own onFocus override). BlackBerry framework should call onFocus on its own. However, you might be misunderstanding when it should be called. For example, if a field already has focus and you call its setFocus again, onFocus will not be called. If you shift focus between two fields controlled by the same Manager, that Manager's onFocus will likewise not be called.

If you are still unsure about why it is happening, show us the relevant code and we might be able to help.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!