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
behrk2
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Help resizing width of EditField on Storm screen tilt

Hi Everyone,

 

I have created a Custom EditField which will keep all of the text on a single line. Everything I have is working fine. When I test the EditField on a Storm simulator and tilt the storm horizontally, however, the EditField will not resize to the new screen width. Can anyone explain to me how I can go about fixing this? The following is my code:

 

 

search2 = new CustomEditField(label, Display.getWidth());
search2.setChangeListener(this)

 

 

 

package com.kflicks.ui.Custom;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class CustomEditField extends VerticalFieldManager {

	private int managerWidth;
	private int managerHeight;
	private EditField editField;

	public CustomEditField(final String label, int width) {

		super(Manager.NO_VERTICAL_SCROLL);
		managerWidth = width;

		VerticalFieldManager vfm = new VerticalFieldManager(
				Manager.VERTICAL_SCROLL);

		editField = new EditField() {
			public void paint(Graphics g) {
				getManager().invalidate();
				super.paint(g);
			}

			protected void onFocus(int direction) {
				if (getText().equals("") || getText().equals(label)) {
					setText("");
				}
			}

			protected void onUnfocus() {
				if (getText().equals(label) || getText().equals("")) {
					setText(label);
				}
			}

		};

		editField.setText(label);
		vfm.add(editField);
		add(vfm);
	}

	public void paint(Graphics g) {
		super.paint(g);

		int oldColor = Color.GRAY;
		// int oldAlpha = g.getGlobalAlpha();

		// g.setGlobalAlpha(0x88);
		g.setBackgroundColor(0x00EF3825);
		g.setColor(0x181818);
		g.fillRect(0, 0, getWidth(), getHeight()); // 8, 8
		g.setColor(oldColor);
		// g.setGlobalAlpha(oldAlpha);
		super.paint(g);
	}

	public void sublayout(int width, int height) {

		if (managerWidth == 0) {
			managerWidth = width;
		}
		if (managerHeight == 0) {
			managerHeight = height;
		}
		super.sublayout(managerWidth, getPreferredHeight());
		setExtent(managerWidth, getPreferredHeight());
	}

	public String getText() {
		return editField.getText();
	}

	public void setText(String text) {
		editField.setText(text);
	}

	protected boolean keyChar(char character, int status, int time) {

		if (character == Keypad.KEY_ENTER) {
			fieldChangeNotify(0);
			return true;
		}

		if (character == Keypad.KEY_ESCAPE) {
			setText("");
			return true;
		}
		return super.keyChar(character, status, time);
	}

}

 

Thanks!

 

Please use plain text.
Developer
behrk2
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Help resizing width of EditField on Storm screen tilt

If it helps, I have also been looking at / implemented the custom EditField listed on the following forum post:

 

http://supportforums.blackberry.com/t5/Java-Development/Stop-edit-field-from-wrapping-text/m-p/25528...

 

But again, the field will not resize to the new display width when tilting the storm...

 

Any suggestions? Thanks!

Please use plain text.
Developer
rakesh86shankar
Posts: 988
Registered: ‎05-22-2009
My Device: Not Specified

Re: Help resizing width of EditField on Storm screen tilt

Hi ,i think what u got is width input given by you.So it will remain the same even though u tilt,but displaywidth will vary when it is tilted,so u cannot get the same result,what u got in verticalform,cannot be obtained as in the horizontal form,so calculate the width from display width

 

 

Regards

Rakesh Shankar.p

Please use plain text.
Developer
behrk2
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Help resizing width of EditField on Storm screen tilt

Thanks for your help. I changed my sublayout() method to the following:

 

 

public void sublayout(int width, int height) {

	super.sublayout(Display.getWidth(), getPreferredHeight());
	setExtent(Display.getWidth(), getPreferredHeight());
}

 

Now it is working.

 

Please use plain text.
New Developer
longmilk
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

Re: Help resizing width of EditField on Storm screen tilt

How to add a label to this CustomEditField, I have tried your constructor but failed??

Please use plain text.