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
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Makes higher a PopupScreen

[ Edited ]

Hi.

I have a custom PopupScreen. Here is some coding:

public class EditLicenciaDialog extends PopupScreen {
	private DialogFieldManager mDfm;
	private EditField efNumeroLicencia;
	private EditField efDescripcion;

	private ButtonField btnOK;
	private ButtonField btnCancel;

   public EditLicenciaDialog() {
       Strign titulo = "Title";
	   
  		mDfm = (DialogFieldManager) getDelegate();
		mDfm.setIcon(new BitmapField(Bitmap
				.getPredefinedBitmap(Bitmap.QUESTION)));
		mDfm.setMessage(new RichTextField(titulo, Field.NON_FOCUSABLE));

		Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(2,
				2, 2, 2), Color.WHITE, Border.STYLE_SOLID);

		efNumeroLicencia = new EditField() {
			protected void paint(Graphics graphics) {
				graphics.setColor(Color.WHITE);
				super.paint(graphics);
			}
		};
		efNumeroLicencia.setBorder(roundedBorder);
		mDfm.addCustomField(new LabelField("Numero:"));
		mDfm.addCustomField(efNumeroLicencia);

		efDescripcion = new EditField() {
			protected void paint(Graphics graphics) {
				graphics.setColor(Color.WHITE);
				super.paint(graphics);
			}
		};
		efDescripcion.setBorder(roundedBorder);
		mDfm.addCustomField(new LabelField("Descripcion:"));
		mDfm.addCustomField(efDescripcion);

		HorizontalButtonFieldSet hfm = new HorizontalButtonFieldSet();
		btnOK = new ButtonField("Aceptar", ButtonField.CONSUME_CLICK
				| ButtonField.HCENTER | Manager.USE_ALL_WIDTH);
		btnOK.setChangeListener(this);
		hfm.add(btnOK);

		btnCancel = new ButtonField("Cancelar", ButtonField.CONSUME_CLICK
				| ButtonField.HCENTER | Manager.USE_ALL_WIDTH);
		btnCancel.setChangeListener(this);
		hfm.add(btnCancel);

		mDfm.add(new SpacerField(0, 10));
		mDfm.addCustomField(hfm);		

   }
   
   ...
   
}

 The problem is that the dialog does not show all the field and I have to scroll to reach the buttons. I would like to increase dialog height to avoid scrolling. I also test chnage the getPreferredHeight of the dialog but it did not work...

 

TIA

Yamil

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Makes higher a PopupScreen

 

Override  sublayout(int width, int height)  method of the PopupScreen and used setExtent(width, height); 

it should work. 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Makes higher a PopupScreen

Yes, overriding sublayout is the way to go. However, PopupScreen has its own idea about its size, so you might want to create it with USE_ALL_WIDTH and USE_ALL_HEIGHT and pass your desired values for width and height into super.sublayout inside your sublayout override. Then you won't need to setExtent and the parent class will not be confused.

----------------------------------------------------------
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
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Makes higher a PopupScreen

Thanks guys.

Now I created the dialog as

super(new DialogFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT)); 

 

Also override sublayout but I am confused about it. When I try :

public void sublayout(int width, int height) {
height*=2;
super.sublayout(width, height);
}

I guess that it will draw the dialog as doubling its height and when i run it, shows half of it!!!

Second, then i change to 

public void sublayout(int width, int height) {
height*=2;
super.sublayout(width, Display.getHeight()-2);
}

It shows the dialog complete but not as heigher as it suggests the code (it must be as tall as the screen)

 

Weird, isn'it ?

 

 

 

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Makes higher a PopupScreen

Take help from the following code but don't use hard code value like 80 etc. Calculate the height of the child and pass.

 

protected void sublayout(int width, int height)
  {
    Field field;
    //get total number of fields within this manager
    int numberOfFields = getFieldCount();     
    int x = 0;
    int y = 0;
    System.out.println("******** Fields: " + numberOfFields + " W/H: " + width + " / " + height );
    for(int i = 0;i < numberOfFields;i++) {
      field = getField(i);      //get the field
      x = 20;
      y = 80;
      System.out.println("******** X/Y: " + x + " / " + y);
      setPositionChild(field, x, y);  //set the position for the field
      layoutChild(field, width, y);  //lay out the field
    }
    setPosition(0, 80);
    setExtent(width, 80);

  }

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Makes higher a PopupScreen

following link might help you

 

http://stackoverflow.com/questions/1426081/creating-custom-layouts-in-blackberry

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Makes higher a PopupScreen

you can also take help from the following code

 

public class ChoicePopupScreen extends PopupScreen {
        Object []choice = null;

        /*holds the position for popup screen*/
        private int  _posX = 0;
        private int _posY = 0;

        public ChoicePopupScreen(int posx,int posy, Object[] choice) {
            /*calling super class constructor*/
            super(new VerticalFieldManager(), Field.FOCUSABLE);

            this.setMargin(new XYEdges(1,1,1,1));

            this.choice = new Object[choice.length];
            this.choice = choice;

            /*Setting position for popup screen*/
            _posX = posx;
            _posY = posy;

            /*list field customized to display as choice picker*/
            ListField choiceList = new ListField(){
                /*list field event handling using navigation click*/
                protected boolean navigationClick(int status, int time) {
                    /*getting the selected list index value*/
                    int index = this.getSelectedIndex();

                    /*returning the selected index to the main field*/
                    setSelIndex(index);

                    /*removing the popup screen from the screen stack*/
                    UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());

                    /*required for event handling*/
                    return super.navigationClick(status, time);
                }
            };

            /*displays the message when list is empty*/
            choiceList.setEmptyString("List is empty", DrawStyle.LEFT);
            choiceList.setSize(choice.length);
            choiceList.setCallback(new PopUpListCallback());            
            add(choiceList);


            Border border = BorderFactory.createSimpleBorder( new XYEdges(), Border.STYLE_TRANSPARENT);
            this.setBorder(border);
        }

        protected void  setChoice(Object []choice) {            
            this.choice = new Object[choice.length];
            this.choice = choice;
        }

        protected void sublayout(int width, int height) {
            super.sublayout(width, height);         
            /*setting the position for the popup screen*/
            setPosition(_posX , _posY);
        }
    }


Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Highlighted
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Makes higher a PopupScreen

Thanks a lot!!!