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
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel
Accepted Solution

Virtual keyboard is hiding the part of the edit Field

Hi,

 

I have a labelfield, Edit Field and a button which are centered align vertically. This three fields i have added in a Verticalfield manager which is then added to a Horizontal Field Manager. And finally the HFM is added to another VFM. Now in the 9800 device or 9380 curve i have observed that when i am touching the Edit field, virtual keypad is coming. And it is hiding the Edit Field partially.

 

I want to move the things up when the virtual keyboard appeared. How can i make it. My code is here:

 

		HorizontalFieldManager hfm = new HorizontalFieldManager();
		VerticalFieldManager vfmComponent = new VerticalFieldManager(USE_ALL_WIDTH);
		vfmComponent.add(lfServerUrl);
		vfmComponent.add(mEfURL);
		vfmComponent.add(mBtnSave);
		hfm.add(vfmComponent);
		int topEmptySpace = (Display.getHeight() - (Bitmap.getBitmapResource(mStrTopBar).getHeight() + hfm.getPreferredHeight() + 25)) / 2;
		hfm.setMargin(topEmptySpace, 0, 0, 0);
		VerticalFieldManager vfmMain = new VerticalFieldManager(VERTICAL_SCROLL| NO_HORIZONTAL_SCROLL );
		vfmMain.add(hfm);
		add(vfmMain);

 Please help.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Virtual keyboard is hiding the part of the edit Field

When you start needing this many managers to achieve the look you want, then you know you really should be creating your own Manager.

 

These two should help you do that:

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

 

As an example, I have hacked together a 'centeringManager' and screen, that should do what you want.  But please use this as a reference sample, understand what it is doing, and perhaps even improve it. 

 

In production code I would actually remove the centeredManager, and have the centering Manager go through all the Fields and position them, but then you need to code up a Manager that understands margins, which would confuse the point of this sample - as a basic implementation of a Manager.

 

Hope this does what you want.

 

public final class CenteringScreen extends MainScreen {

	/**
	 * verticallyCenteringManager takes one Field and positions it
	 * centered in the space it has.
	 */
	VerticalFieldManager centeringManager = new VerticalFieldManager() {
		protected void sublayout(int maxWidth, int maxHeight) {
			if ( this.getFieldCount() > 1 ) {
				throw new RuntimeException("Expecting only one Field or Manager to be added");
			}
			if ( this.getFieldCount() == 1 ) {
				Field f = this.getField(0);
				layoutChild(f, maxWidth, maxHeight);
				int requiredTopMargin = (maxHeight - f.getHeight())/2;
				int requiredLeftMargin = (maxWidth - f.getWidth())/2;
				setPositionChild(f, requiredLeftMargin, requiredTopMargin);
				setExtent(maxWidth, maxHeight);
			} else {
				setExtent(0, 0);
			}
		}
	};

	/**
	 * Fields added to centeredManager will be displayed 'centered' vertically
	 * regardless of orientation of screen and presence or absence
	 * of virtual keyboard
	 */
	VerticalFieldManager centeredManager = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR);
     
    // Sample Fields to be added
	ButtonField sampleButton = new ButtonField("Button", ButtonField.FIELD_HCENTER);
	LabelField sampleLabel = new LabelField("Label", LabelField.FIELD_HCENTER);
	BasicEditField sampleBef = new BasicEditField("Text", "", 255, BasicEditField.FIELD_HCENTER);
	
	public CenteringScreen() {        
        
        super(Manager.NO_VERTICAL_SCROLL); // very important
        // The NO_VERTICAL_SCROLL means that the only Manager added to this Screen - centeringManager -
        // will be given as its maxHeight, the available screen height, regardless of
        // orientation or whether there is a virtual keyboard displayed
        
        // add Fields to centeredManager
        centeredManager.add(sampleButton);
        centeredManager.add(sampleLabel);
        centeredManager.add(sampleBef);
        centeringManager.add(centeredManager);
        this.add(centeringManager);

    }

}

 

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Virtual keyboard is hiding the part of the edit Field

Thanks. It works. Yes instead of adding so many managers, doing with one manager is better or best in this case. Thanks a lot.

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Virtual keyboard is hiding the part of the edit Field

But one thing i observed. When i am coming to the screen and Edit field is focussed, virtual keyboard is not displaying. If i am touching the editfield, it is showing the virtual keyboard.

Please use plain text.
Trusted Contributor
Sankar_S
Posts: 139
Registered: ‎08-22-2013
My Device: None
My Carrier: Aircel

Re: Virtual keyboard is hiding the part of the edit Field

This really useful help to improve this post another way

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Virtual keyboard is hiding the part of the edit Field

I don't think the EditField displaying or not displaying the virtual keyboard is a function of the manager involved.  However if you wish to force the keyboard to be displayed when the EditField is focused, you can do that.  Personally I would ensure that the focus was elsewhere on initial display.

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Virtual keyboard is hiding the part of the edit Field

So if my initial display is Edit Field, i hope it should display the virtual keyboard. If i need to do the same, then what code i should follow as i am using the custom Edit Field.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Virtual keyboard is hiding the part of the edit Field

@Sankar_S - sorry I have no idea if you are asking for something more or just saying this is a useful post.  Please explain what you want if you think the post could be improved.  . 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Virtual keyboard is hiding the part of the edit Field

@arindamhit

 

The best solution as far as I am concerned is not to put the focus on that Field initially.  Add a NullField above it that will take the focus on the initial screen display.  Then the standard processing should show and hide the keyboard as focus is moved

 

There are various Threads on the forum that talk about showing and hiding the keyboard.  Search for these, if adding the NullField is not good enough as a solution. 

Please use plain text.