03-10-2010 03:31 PM
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!
03-11-2010 03:31 AM
If it helps, I have also been looking at / implemented the custom EditField listed on the following forum post:
But again, the field will not resize to the new display width when tilting the storm...
Any suggestions? Thanks!
03-11-2010 06:40 AM
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
03-11-2010 11:36 AM
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.
09-06-2010 08:11 AM
How to add a label to this CustomEditField, I have tried your constructor but failed??