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
Posts: 18
Registered: ‎04-10-2013
My Device: 9900
My Carrier: xxxx

CustomScrollTextField - Scroll Issue

hi

i have scrollable text field.
in that i want the scroll to be enabled when editfield has the maximum character(end of editfield)
but for me with in a five character the scroll was enabled. plz help

 

 

Here is the code which we are using .....

 

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.ScrollChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.VirtualKeyboard;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class CustomTextField extends HorizontalFieldManager implements ScrollChangeListener {

private EditField _editField;
private String errorString;

String prompt;
HorizontalFieldManager textMgr;

boolean isPasswordField = false;

public CustomTextField(String label, String initialValue, int maxChars, long style) {
this(label, initialValue, maxChars, style, "");
}

public CustomTextField(String label, String initialValue, int maxChars, long style,
String errorString) {
this.setErrorString(errorString);
textMgr = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL);
textMgr.setScrollListener(this);
_editField = new EditField("", initialValue, maxChars, style | EditField.NO_NEWLINE
| EditField.FOCUSABLE | EditField.EDITABLE | EditField.NO_COMPLEX_INPUT
| EditField.NON_SPELLCHECKABLE) {
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x00000000);

String test = this.getText();
if (test == null || test.length() < 1) {
g.setColor(Color.ORANGE);
g.drawText(prompt, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
textMgr.add(_editField);
add(textMgr);
}

public void setPrompt(String prompt) {
this.prompt = prompt;
}

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

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

public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) {
// TODO Auto-generated method stub
if (!isFocus()) {
manager.setHorizontalScroll(0, false);
}
};

protected boolean navigationMovement(int dx, int dy, int status, int time) {

if (dx > 0
&& ((_editField != null) && (_editField.getTextLength() == _editField
.getCursorPosition()))) {
if (dy != 0) {
return super.navigationMovement(0, dy, status, time);
}
releaseFocus();
return true;
}

return super.navigationMovement(dx, dy, status, time);
}

protected void releaseFocus() {

}

public String getErrorString() {
return errorString;
}

public void setErrorString(String errorString) {
this.errorString = errorString;
}

protected boolean keyChar(char character, int status, int time) {
if (character == Characters.ENTER) {
if (VirtualKeyboard.isSupported() == true) {
UiApplication.getUiApplication().getActiveScreen().getVirtualKeyboard()
.setVisibility(VirtualKeyboard.HIDE);
}
return true;
}
return super.keyChar(character, status, time);
}

}