I have two VerticalFieldManager
which are in HorizontalFieldManager
to make two columns with images inside. Those images are able to focus (Blackberry add border to image when focus) with border, but there is one problem, when I scroll from right to left and opposite focus skip to the top image in VerticalFieldManager
how to avoid it and skip to the nearest left/right image? Part responsible for adding images:
for(int i=0;i<15;++i){
if(i%2==0){
v1.add(tab[i]);
}else{
v2.add(tab[i]);
}
}
The reason for this is because your managers can only enter focus from 2 directions. For a HorizontalFieldManager
its left and right, while VerticalFieldManager
is top and bottom. When you scroll in your horizontal manager to the left, you are moving in a -1 direction. This is then passed to your vertical manager, where -1 means that it gets focus from the bottom. Likewise when you move to the right, it is in the +1 direction and focuses from the top.
The best bet for you would be to listen for navigation movement (on the horizontal manager), and then focus the correct field programmatically.
HorizontalFieldManager horManager = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL | USE_ALL_WIDTH | USE_ALL_HEIGHT)
{
protected boolean navigationMovement(int dx, int dy, int status, int time)
{
if(dx > 0 && leftManager.isFocus()) // Moved right from the left manager
{
int index = leftManager.getFieldWithFocusIndex();
rightManager.getField(index).setFocus();
return true;
}
else if(dx < 0 && rightManager.isFocus())// Moved left from the right manager
{
int index = rightManager.getFieldWithFocusIndex();
leftManager.getField(index).setFocus();
return true;
}
return super.navigationMovement(dx, dy, status, time);
}
};
This assumes that both vertical managers contain the same number of fields and only two columns. But with a little bit of work, you can make this method handle a dynamic number of vertical managers, and fields.