BlackBerry - line not showing
I am having a problem with EditField
.
I have created an EditField
using this code under a "HorizontalFieldManager".
EditField nameEditLabel = new EditField (EditField.FOCUSABLE
| EditField.NO_NEWLINE | EditField.FIELD_RIGHT);
nameEditLabel.setMaxSize(25);
nameEditLabel.setMargin(50, 0, 0, 80);
horizontalFldManager.add(nameEditLabel);
Problem now is, On the screen, it doesn't show the line of the field. Somethin开发者_开发问答g like, basically a Field contain "Name: ----------------------" such line in other platform controls, which is not showing here on the screen. What is the problem here? Is it default in API support? If no, how do i resolve it?
Note: This line is getting created only when i write something on the field.
Thanks.
If you want to have this "----" in case EditField is empty, extend it to implement check value logic:
class LabelFieldEmpty extends EditField {
String mEmptyText = "";
public LabelFieldEmpty(long style) {
super(style);
}
public void setEmptyText(String emptyText) {
mEmptyText = emptyText;
}
public String getEmptyText() {
return mEmptyText;
}
protected boolean keyChar(char key, int status, int time) {
if (null != mEmptyText)
if (getText().equalsIgnoreCase(mEmptyText)) {
setText(String.valueOf(key));
return true;
}
return super.keyChar(key, status, time);
}
protected void fieldChangeNotify(int context) {
if (null != mEmptyText)
if (!getText().equalsIgnoreCase(mEmptyText))
if (getText().equalsIgnoreCase("")) {
setText(mEmptyText);
setCursorPosition(0);
}
super.fieldChangeNotify(context);
}
}
Example of use:
class Scr extends MainScreen {
public Scr() {
String label = "Name:";
String empty = "-------------------------";
int maxChars = 25;
long style = EditField.FOCUSABLE | EditField.NO_NEWLINE
| EditField.FIELD_RIGHT;
LabelFieldEmpty nameEdit = new LabelFieldEmpty(style);
nameEdit.setLabel(label);
nameEdit.setMaxSize(maxChars);
nameEdit.setMargin(50, 0, 0, 80);
nameEdit.setEmptyText(empty);
add(nameEdit);
}
}
精彩评论