自EditField中不显示所有键入的文本 [英] Custom editfield not displaying all typed text
问题描述
下面类是一个文本框字段。这可以被修改,使得当文本框填充有文本和用户保持键入然后将文本滚动?请告诉我现在发生的事情是,一旦文本框充满文本未显示键入任何后续文本。
感谢
进口net.rim.device.api.ui.Color;
进口net.rim.device.api.ui.Font;
进口net.rim.device.api.ui.Graphics;
进口net.rim.device.api.ui.component.EditField;公共类CustomEditField扩展EditField中{
在CustomEditField类//私有成员
私人字体defaultFont;
//用来获取默认字体
私人字符串文本; //用于指定表格单元格中的默认宽度 //构造函数调用父类的构造函数
公共CustomEditField(字符串标签,字符串初值,诠释maxNumChars,
长样式){
超(标签,初值,maxNumChars,风格);
} //覆盖默认的get preferredWidth功能返回一个固定
//宽
公众诠释的get preferredWidth(){
defaultFont = Font.getDefault();
文字=0000000000;
返回defaultFont.getAdvance(文本); } //覆盖默认的布局功能来设置表格的宽度
// 细胞
保护无效布局(INT宽度,高度INT){
宽度= GET preferredWidth();
高度= super.get preferredHeight();
super.layout(宽度,高度);
//使用超类的布局功能
//后的宽度和高度被设置
super.setExtent(宽度,高度);
//使用超类setExtent功能
//后的宽度和高度被设置
} 公共无效漆(图形图像){ graphics.setBackgroundColor(Color.LIGHTBLUE);
super.paint(图形);
}}
这将帮助你上手。这是,我现在用的是 ScrollableEditField的简化版本。我$ C $光盘,它的触摸BlackBerry设备面世之前,因此一些额外的工作,这里需要支持
的TouchEvent
秒。
类ScrollableEditField扩展管理器{
私人最终静态INT DEFAULT_TOP_PADDING = 1;
私人最终静态INT DEFAULT_BOTTOM_PADDING = 1;
私人最终静态INT DEFAULT_LEFT_PADDING = 1;
私人最终静态INT DEFAULT_RIGHT_PADDING = 1; 私人INT TOTAL_VERTICAL_PADDING = DEFAULT_TOP_PADDING + DEFAULT_BOTTOM_PADDING;
私人INT TOTAL_HORIZONTAL_PADDDING = DEFAULT_LEFT_PADDING + DEFAULT_RIGHT_PADDING; 私人诠释宽度= -1;
私人诠释高度= -1; 私人HorizontalFieldManager HFM =新HorizontalFieldManager(HORIZONTAL_SCROLL);
私人EditField中EF; 公共ScrollableEditField(字符串标签,字符串初值,INT maxNumChars,长innerEditFieldStyle){
超(NO_HORIZONTAL_SCROLL);
EF =新EditField中(标签,初值,maxNumChars,innerEditFieldStyle);
hfm.add(EF);
加(HFM);
} 保护无效sublayout(INT宽度,高度INT){
如果(this.width!= -1){
宽度= this.width;
} 如果(this.height!= -1){
高度= this.height;
}其他{
身高= ef.getFont()的getHeight()。
} layoutChild(HFM,宽度TOTAL_HORIZONTAL_PADDDING,高度TOTAL_VERTICAL_PADDING);
setPositionChild(HFM,DEFAULT_LEFT_PADDING,DEFAULT_TOP_PADDING);
setExtent(宽度,高度);
} 公共EditField中getEditField(){
返回EF;
} 公共无效setWidth(int width)将{
this.width =宽度;
} 保护无效的onfocus(INT方向){
super.onFocus(方向);
ef.setCursorPosition(0);
} 保护无效onUnfocus(){
hfm.setHorizontalScroll(0);
super.onUnfocus();
}
};公共类ScrollableEditFieldScreen扩展MainScreen {
公共ScrollableEditFieldScreen(){
超(NO_VERTICAL_SCROLL);
的setTitle(ScrollableEditField); // hfm1和hfm2在这里只是为了ScrollableEditField在屏幕的中心位置
HorizontalFieldManager hfm1 =新HorizontalFieldManager(USE_ALL_HEIGHT | FIELD_HCENTER);
HorizontalFieldManager hfm2 =新HorizontalFieldManager(FIELD_VCENTER); //实例化滚动编辑字段,添加边框
ScrollableEditField SEF =新ScrollableEditField(,,50,0);
sef.setBorder(BorderFactory.createRoundedBorder(新XYEdges(5,5,5,5)));
sef.setWidth(sef.getFont()getAdvance('0')* 10); hfm2.add(SEF);
hfm1.add(hfm2);
加(hfm1);
}
}
Below class is a textbox field. Can this be modified so that when the textbox is filled with text and user keeps type the text then scrolls ? Whats happening now is that once the textbox is filled with text any subsequent text that is typed is not being displayed.
Thanks
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.EditField;
public class CustomEditField extends EditField {
// private members of the CustomEditField class
private Font defaultFont;
// used to get the default font
private String text;
// used to specify the default width of the table cells
// constructor calls the super class constructor
public CustomEditField(String label, String initialValue, int maxNumChars,
long style) {
super(label, initialValue, maxNumChars, style);
}
// overrides the default getPreferredWidth functionality to return a fixed
// width
public int getPreferredWidth() {
defaultFont = Font.getDefault();
text = "0000000000";
return defaultFont.getAdvance(text);
}
// overrides the default layout functionality to set the width of the table
// cell
protected void layout(int width, int height) {
width = getPreferredWidth();
height = super.getPreferredHeight();
super.layout(width, height);
// uses the super class' layout functionality
// after the width and the height are set
super.setExtent(width, height);
// uses the super class' setExtent functionality
// after the width and the height are set
}
public void paint(Graphics graphics){
graphics.setBackgroundColor(Color.LIGHTBLUE);
super.paint(graphics);
}
}
This will help you to get started. It is a simplified version of the ScrollableEditField
that I am using. I coded it before touch BlackBerry devices became available, therefore some additional work is required here to support TouchEvent
s.
class ScrollableEditField extends Manager {
private final static int DEFAULT_TOP_PADDING = 1;
private final static int DEFAULT_BOTTOM_PADDING = 1;
private final static int DEFAULT_LEFT_PADDING = 1;
private final static int DEFAULT_RIGHT_PADDING = 1;
private int TOTAL_VERTICAL_PADDING = DEFAULT_TOP_PADDING + DEFAULT_BOTTOM_PADDING;
private int TOTAL_HORIZONTAL_PADDDING = DEFAULT_LEFT_PADDING + DEFAULT_RIGHT_PADDING;
private int width = -1;
private int height = -1;
private HorizontalFieldManager hfm = new HorizontalFieldManager(HORIZONTAL_SCROLL);
private EditField ef;
public ScrollableEditField(String label, String initialValue, int maxNumChars, long innerEditFieldStyle) {
super(NO_HORIZONTAL_SCROLL);
ef = new EditField(label, initialValue, maxNumChars, innerEditFieldStyle);
hfm.add(ef);
add(hfm);
}
protected void sublayout(int width, int height) {
if (this.width != -1) {
width = this.width;
}
if (this.height != -1) {
height = this.height;
} else {
height = ef.getFont().getHeight();
}
layoutChild(hfm, width-TOTAL_HORIZONTAL_PADDDING, height-TOTAL_VERTICAL_PADDING);
setPositionChild(hfm, DEFAULT_LEFT_PADDING, DEFAULT_TOP_PADDING);
setExtent(width, height);
}
public EditField getEditField() {
return ef;
}
public void setWidth(int width) {
this.width = width;
}
protected void onFocus(int direction) {
super.onFocus(direction);
ef.setCursorPosition(0);
}
protected void onUnfocus() {
hfm.setHorizontalScroll(0);
super.onUnfocus();
}
};
public class ScrollableEditFieldScreen extends MainScreen {
public ScrollableEditFieldScreen() {
super(NO_VERTICAL_SCROLL);
setTitle("ScrollableEditField");
// hfm1 and hfm2 are here just to position the ScrollableEditField in the center of the screen
HorizontalFieldManager hfm1 = new HorizontalFieldManager(USE_ALL_HEIGHT | FIELD_HCENTER);
HorizontalFieldManager hfm2 = new HorizontalFieldManager(FIELD_VCENTER);
// instantiating the scrollable edit field and adding border
ScrollableEditField sef = new ScrollableEditField("", "", 50, 0);
sef.setBorder(BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5)));
sef.setWidth(sef.getFont().getAdvance('0')*10);
hfm2.add(sef);
hfm1.add(hfm2);
add(hfm1);
}
}
这篇关于自EditField中不显示所有键入的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!