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
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Device: BlackBerry Bold

Setting Focus to A Field Based On Coordinates X & Y

[ Edited ]

Custom Pointer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Hi, I want to create an arrow pointer like the one shown on the BrowserField. To do this, I'm using an AbsoluteFieldManager to layout the fields and also the arrow pointer itself. I have overridden the original navigationMovement method so that instead of moving focus to another field, it moves the arrow pointer's position and then repaints the entire screen.

 

The problem right now is, I don't know how to set focus to a field based on the coordinates of the arrow pointer.

 

I tried using:

setFieldWithFocus(getField(getFieldAtLocation(x, y))); 

before invalidating the screen, but that didn't seem to work.

 

Can somebody help me with this?

 

Thanks in advance.

Developer
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Device: BlackBerry Bold

Re: Setting Focus to A Field Based On Coordinates X & Y

It seems the ButtonFields aren't receiving focus because they're placed within a HorizontalFieldManager. So when I try to get the Field at the specified coordinates using getFieldAtLocation(x,y), it returns the HorizontalFieldManager and not the ButtonField inside it.

 

I can get the ButtonFields to receive focus by using:

int index = hfm.getFieldAtLocation(x, y);

if (index > -1)
{
	Field f = hfm.getField(index);
	f.setFocus();
}
else
{
	nullField.setFocus();
}

But then I would have a problem if I wanted to select a Field placed within another manager within the HorizontalFieldManager.

 

Is there a way to get retrieve a non-manager field at a specified coordinate?

 

Thanks in advance.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Setting Focus to A Field Based On Coordinates X & Y

Sorry, just a quick answer here that may be wrong.

 

You can keep if then Field you get back is a Manager or not.  if it is a manager, then you need to adjust the x and y according whereabouts that Manager actually starts, and then call getFieldAtLocation again. I think you should be able to do this recursively until you hit a real Field.

 

But you might find you do not in fact get a Field, because the user has hit outside the bounds of all fields.  Not sure how you want to handle that.