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
Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified
Accepted Solution

instanceof to check field focus

I'm using an if (instanceof....) to check if a field that im hovering is focused, then i want to cast that field to what it should be and do things with it.

 

					Field fieldWithFocus = getFieldWithFocus().getLeafFieldWithFocus();

						if (fieldWithFocus instanceof GameItem)
						{

 

but fieldwithFocus never goes into that if statement.


when I view the class, its definately a "GameItem", but it also has a $1 after it (GameItem$1)

 

There are multiple GameItem's on the screen - does the $1 make it "not" a GameItem class?

 

How do i detect that it is a "gameitem" ?

 

thanks

Developer
lakshman9687
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10

Re: instanceof to check field focus

Hi,

 

That one is correct,but u have to give just

Field f = getLeafFieldWithFocus(); thats enough, and u better check with manager or label or name it will work..

 

Regards,

Lakshman K

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

Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified

Re: instanceof to check field focus

hmm, I'm still having issues with this. It's still not detecting its an "instanceof"

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: instanceof to check field focus

$1 hints at the field in question being an anonymous inner class of GameItem, is GameItem a manager? If yes, getLeafFieldWithFocus returns the field with focus.
----------------------------------------------------------
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.
@SimonHain on twitter
Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified

Re: instanceof to check field focus

Ah yes, GameItem is a manager.

 

So.. what would a good solution be?

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: instanceof to check field focus

check for the focused field, not the manager.
If you want to check for the manager you can use getManager on the field (if there is only 1 tier).

you can also check getFieldWithFocus, not sure but it could return the manager, better check that as i always use getLeaf...
----------------------------------------------------------
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.
@SimonHain on twitter
Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified

Re: instanceof to check field focus

If I'm just checking for the focused field (lets say, its a NullField), then would i have to cast as nullfield? I want to be able to cast as GameItem so i can get info from it...

Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: instanceof to check field focus

to get gameitem you will need to do as simon suggested.....call getLeafFieldWithFocus().getManager() then check that for being a GameItem if you only have level. If you have more than one, you'll need to recursively get the managers until you get your GameItem.
Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified

Re: instanceof to check field focus

oh gotcha..i was using getManager without the leaffocus.

 

Works perfect, thanks.