10-16-2009 03:11 PM
I've created a new Field Manager that extends VerticalFieldManager that takes two Fields and places one on the far left hand side of the screen and the other on the far right hand side of the screen. It places them in the right locations and when you scroll down (using the arrow keys) it highlights each field in its proper order.
The problem is that when I use this Field Manager on the BB Storm simulator, I can't focus on the left Field by clicking it. The right field will function properly though.
Is there something else I need to overwrite to fix this?
public class DualFieldManager extends VerticalFieldManager{
Field left;
Field right;
public DualFieldManager(Field l, Field r) {
//construct a manager with vertical scrolling
super();
left = l;
right = r;
add(left);
add(right);
}
protected void sublayout(int width, int height){
//add the left field
layoutChild(left, width, height);
setPositionChild(left, 0, 0);
//add the right field
layoutChild(right, width, height);
setPositionChild(right, width - right.getPreferredWidth(), 0);
//setExtent(width, height);
setExtent(getPreferredWidth(), getPreferredHeight());
}
public int getPreferredWidth(){
return Display.getWidth();
}
public int getPreferredHeight(){
if(left.getHeight() >= right.getHeight()){
return left.getHeight();
}
else{
return right.getHeight();
}
}
}
Solved! Go to Solution.
10-16-2009 03:24 PM
Hello,
you need to implement the navigationMovement method. You can do something like this :
protected boolean navigationMovement(int dx, int dy, int status, int time) {
if (dx > 0 && right.isFocusable()) {
right.setFocus();
}
if (dx < 0 && left.isFocusable()) {
left.setFocus();
}
}
*The code wasn't tested.
10-16-2009 03:31 PM - edited 10-16-2009 03:43 PM
Thanks! This seems to be what I'm looking for.
What does the returned boolean represent and where is this method inherited from?
10-16-2009 03:47 PM - edited 10-16-2009 03:48 PM
The method come from the Field class.
All you need to know is here :
http://www.blackberry.com/developers/docs/4.5.0api
10-16-2009 03:56 PM
Well, now I can use the left and right arrow keys to toggle between the left and right fields (which is certainly a plus), but I still can't focus on the left by clicking on it.
Is there any type of onClick function I could use to affect the Manager's behavior?
10-16-2009 04:09 PM - edited 10-16-2009 04:16 PM
I can't figure out what you're trying to do, but if the field is not a button, the click is unhandle at the manager level then the screen will handle it. Often the field will lose focus if the screen handle the click.
Other point, you should use getWidth in the setPositionChild method as the preferred width isn't the actual size of the field.
10-16-2009 04:14 PM - edited 10-16-2009 04:38 PM
Currently I'm using a CheckboxField as the left and right Fields. Clicking the right checkbox will focus and toggle it. Clicking on the left checkbox yields no results.
I just changed the left field to a button, but clicking it will yield no results either (a button without a listener should still light up while you're clicking it).
DualFieldManager temp;
temp= new DualFieldManager(new ButtonField("button"), new CheckboxField("test", true));
add(temp);
So basically it looks like this:
______________________________________
|
| Field
|
10-16-2009 05:13 PM
Fixed it. I made my manager extend Manager instead of VerticalFieldManager and now the left field is accessible by clicking on it.
Thanks for your help.
12-20-2011 03:04 AM
Your solution worked perfectly ![]()
Can you please give me some insight into what really happens (in context of the problem discussed) when a Manager is used instead of a VerticalFieldManager/HorizontalFieldManager?