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
ubuntaur
Posts: 41
Registered: ‎09-11-2009
My Device: Not Specified
Accepted Solution

Custom FieldManager Focus Problem

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();
       }
   }
}

 

 

Please use plain text.
Developer
SamuelD
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Custom FieldManager Focus Problem

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.

 

Thank you, have a nice day.

--
Samuel D.
Please use plain text.
Developer
ubuntaur
Posts: 41
Registered: ‎09-11-2009
My Device: Not Specified

Re: Custom FieldManager Focus Problem

[ Edited ]

Thanks! This seems to be what I'm looking for.

 

What does the returned boolean represent and where is this method inherited from?

Please use plain text.
Developer
SamuelD
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Custom FieldManager Focus Problem

[ Edited ]

The method come from the Field class.

All you need to know is here :

 

http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Field.html

Thank you, have a nice day.

--
Samuel D.
Please use plain text.
Developer
ubuntaur
Posts: 41
Registered: ‎09-11-2009
My Device: Not Specified

Re: Custom FieldManager Focus Problem

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?

Please use plain text.
Developer
SamuelD
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Custom FieldManager Focus Problem

[ Edited ]

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.

Thank you, have a nice day.

--
Samuel D.
Please use plain text.
Developer
ubuntaur
Posts: 41
Registered: ‎09-11-2009
My Device: Not Specified

Re: Custom FieldManager Focus Problem

[ Edited ]

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

|                                                                                       |

 

 

Please use plain text.
Developer
ubuntaur
Posts: 41
Registered: ‎09-11-2009
My Device: Not Specified

Re: Custom FieldManager Focus Problem

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.

Please use plain text.
Contributor
Dsheel
Posts: 24
Registered: ‎01-24-2011
My Device: 4.2.1(8800), 4.6(9000), 4.7 and above

Re: Custom FieldManager Focus Problem

Your solution worked perfectly :smileyhappy:

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?

Please use plain text.