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
Contributor
shujaathussain
Posts: 14
Registered: ‎01-10-2011
My Device: Not Specified
Accepted Solution

Custom Manager

Hi,

 

 

I need to create a layout which contains a Button on the left corner, an image in the middle and another button on the left most corner:

 

------------------------------------------------------------------

|Button|                       |Image|                        |Button|

------------------------------------------------------------------

 

I created my own manager but its not working on all the devices. Here is my code:

 

 

public class NavigationBarLayout extends Manager {

	public NavigationBarLayout(){
		super(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_VERTICAL_SCROLL | Manager.USE_ALL_WIDTH);
	}
	// TODO Auto-generated constructor stub}

	protected void sublayout(int width, int height) {
		// TODO Auto-generated method stub
		
        Field field;
        //get total number of fields within this manager
        int numberOfFields = getFieldCount();
        for (int i = 0; i < numberOfFields; i++) 
        {
            field = getField(i);     //get the field
            switch (i) {
	            case 0:
		            setPositionChild(field,0,5);  //set the position  for the field
		            layoutChild(field, width, height);  //lay out the field
	            	break;
	            case 1: // Post code edit field.
		            setPositionChild(field,(Display.getWidth()/3) - field.getWidth(),5);  //set the position  for the field
		            layoutChild(field, width, height);  //lay out the field
	            	break;
	            case 2: // Location search.
		            setPositionChild(field,Display.getWidth() - field.getWidth(),5);  //set the position  for the field
		            layoutChild(field, width, height);  //lay out the field
	            	break;
            }
        }
		
        setExtent(width, 50);
	}

}

 

 

Anybody Please help me!

 

TIA

 

 

 

New Contributor
Rrupak
Posts: 8
Registered: ‎08-23-2010
My Device: Not Specified

Re: Custom Manager

[ Edited ]

Hi   shujaathussain,

 

You may need to change positioning calculation (x-position) for the second field. Your code works on my side with following changes (I assume that any of these three field will not have a width greater than one third of the manager's width).

 

protected void sublayout(int width, int height) {

   Field field;
   int numberOfFields = getFieldCount();
   int xPosFinal = 0, yPosFinal = 5;
   for (int i = 0; i < numberOfFields; i++) {
      field = getField(i);     
      switch (i) {
         case 0:
            xPosFinal = 0;  
            break;
         case 1:                     
            // need to add available
            // width of the first field
            xPosFinal = (Display.getWidth() / 3);
            xPosFinal += ((Display.getWidth() / 3) - field.getWidth()) / 2;                     
            break;
         case 2:
            xPosFinal = Display.getWidth() - field.getWidth();  
            break;
      }   
      setPositionChild(field, xPosFinal, yPosFinal);
      layoutChild(field, width, height);  
   }
   
   setExtent(width, 50);
}

 

 

Contributor
shujaathussain
Posts: 14
Registered: ‎01-10-2011
My Device: Not Specified

Re: Custom Manager

Hi Rrupak,

 

Thanks for the reply. I tried your code on four different simulators but its not working. Image that is supposed to be in the center has moved more to the right and the button that is supposed to be in the right corner is not visible (moved out the screen)

 

I changed it a little bit:

 

 

protected void sublayout(int width, int height) {

Field field; int numberOfFields = getFieldCount(); for (int i = 0; i < numberOfFields; i++) { field = getField(i); switch (i) { case 0: setPositionChild(field,0,5); layoutChild(field, width, height); break;
case 1: setPositionChild(field,(Display.getWidth()/2)- title.getWidth()/2,5); layoutChild(field, width, height);
break;
case 2:
setPositionChild(field,Display.getWidth() - field.getWidth(),5); layoutChild(field, width, height); break;
}
} setExtent(width, 38);
}

For displaying image in center of the screen, I created a bitmap field  using the image which is supposed to be in the center(just for getting its width) and then calculated the x-dimensions for it in Case 1.

 

Left most button and center image are fine now but the only problem is right-most button. Its not visible i.e. its out of the screen width.

 

 


 


Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Custom Manager

If you put layoutChild before getting its width (in setPositionChild) your results will be much better.

 

The reason for this is simple - before the field has been laid out, its height and width are at their default values - meaning zero!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
rnickel
Posts: 62
Registered: ‎10-29-2008
My Device: 9800

Re: Custom Manager

I would recommend you use the TableLayoutManager, or even GridManager classes. They will each allow the field itself to decide it's alignment within the cell

Contributor
shujaathussain
Posts: 14
Registered: ‎01-10-2011
My Device: Not Specified

Re: Custom Manager

Hi arkadyz,

 

Thanks alot for the help. It did the same as you suggested and the problem is solved.

 

Thanks.

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Custom Manager

Good for you!

 

Could you mark the thread as solved then?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!