i just made this example for the sake of my question.
public MyScreen()
{
setTitle("GridFieldManager");
GridFieldManager grid2 = new GridFieldManager(1,2,GridFieldManager.FIXED_SIZE);
add(grid2);
String[] choice={"1","2","0"};
ObjectChoiceField menu=new ObjectChoiceField(null,choice);
//grid.add(lol);
grid2.add(new LabelField("Productos_",NON_FOCUSABLE));
grid2.add(menu);
}
For some reason i still can focus the labelfield even when i said it was non focusable (Field.NON_FOCUSABLE
).
Note: Just to let you know, i'm using a label + objectchoicefield so i can have total control of the properties of that label, since i found troublesome changing the color and font from the label that objectchoicefield has.
In this picture you can see how the focus is on the LabelField
. i just want to focus the objectchoicefield list.
Honestly, to me, this seems like a bug. I don't think it should work this way. However, at this point, nothing in older BlackBerry Java devices is going to be fixed, so we just have to work around it.
The problem is that you have set your
LabelField
to be non-focusable, but the device is ignoring that. It is opening your screen with focus on theGridFieldManager
, which just puts focus on its first field (the label). If the user moves focus onto the choice field, you won't be able to get focus back to the label field. But, I'm sure you don't want the screen opening with focus on something non-focusable.You can either just set focus manually to the choice field:
or, if you want to handle this more generically, you can write your own method to initialize the focus to the first field that's really focusable:
Both solutions should work for you.
Note: by the way, you don't have to actually set the
LabelField
to be non-focusable. It will be non-focusable by default. It doesn't hurt. It's just not needed.Update:
If you also want to be able to set focus back to
grid2
later (after the screen first appears), you can also call myinitializeFocus()
method again, to prevent any more problems with the non-focusable label gaining focus.For example, make your screen
implement FocusChangeListener
, and then in its constructor:where the focus listener implementation includes this new method (in your screen class):
This will allow
initializeFocus()
to be called for thegrid2
manager object, if focus is later set back to it. CallinginitializeFocus()
, passing the grid field manager as the argument, will correctly set focus to its first focusable field.