0
下面的類是一個文本框字段。這可以修改,以便當文本框填充文本和用戶保持鍵入文本然後滾動?現在發生的事情是,一旦文本框被填充文本,任何後續輸入的文本都不會被顯示。自定義編輯字段不顯示所有鍵入的文本
感謝
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);
}
}
我不說這是不可能的,但是我相信,有沒有簡單的方法,因爲你將需要覆蓋'油漆(圖形圖像)'行爲一起選擇與跟蹤領域內的插入位置。我還隱約想起有人通過在啓用滾動的情況下在'HorizontalFieldManager'內包裝'EditField'實現了這一點,但是該解決方案也有點臭。我的建議 - 如果可以的話避免這種情況。 – 2011-03-20 00:04:27
只是一個想法(未測試) - 可能使用嵌入式瀏覽器字段將允許得到你想要的? – 2011-03-20 00:06:51
對我而言,這似乎很奇怪,因爲用戶在文本框中鍵入的文本多於文本框的容量是標準行爲,所以這並未實現。 – 2011-03-31 16:09:09