すべてのタイプされたテキストを表示しないカスタム編集フィールド

StackOverflow https://stackoverflow.com/questions/5355515

  •  27-10-2019
  •  | 
  •  

質問

以下のクラスはテキストボックスフィールドです。テキストボックスがテキストで満たされ、ユーザーがテキストを入力してからスクロールし続けるように、これを変更できますか?現在起こっているのは、テキストボックスにテキストが満たされると、入力された後続のテキストが表示されていないことです。

ありがとう

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);
    }

}
役に立ちましたか?

解決

これはあなたが始めるのに役立ちます。これは単純化されたバージョンです ScrollableEditField 私が使っていること。 Touch BlackBerryデバイスが利用可能になる前にコーディングしたので、ここでサポートするためにいくつかの追加作業が必要です TouchEvents。

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);
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top