Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 基本字段自定义_Blackberry_User Interface - Fatal编程技术网

Blackberry 基本字段自定义

Blackberry 基本字段自定义,blackberry,user-interface,Blackberry,User Interface,我想要一个基本的编辑字段,其中输入的第一个字符位于最右边的位置…类似这样的 2 23 234 有人能告诉我怎么做吗…使用样式字段。字段(右)。使用样式字段。字段(右)。非常肯定没有内置的方法来做这件事,你必须实现你自己的文本框非常肯定没有内置的方法来做这件事,您必须实现自己的文本框,这里有一种方法: import net.rim.device.api.system.Characters;

我想要一个基本的编辑字段,其中输入的第一个字符位于最右边的位置…类似这样的

                  2

                 23

                234

有人能告诉我怎么做吗…

使用样式字段。字段(右)。

使用样式字段。字段(右)。

非常肯定没有内置的方法来做这件事,你必须实现你自己的文本框

非常肯定没有内置的方法来做这件事,您必须实现自己的文本框,这里有一种方法:

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.BasicEditField;

public class RightInsertTextField extends BasicEditField {
    private String lastGoodTxtInputEntry = null;
    private int maxCharInputLength = 20;
    private Field nextFieldForFocus = null;

/**
 * Basic constructor.
 * 
 * @param defaultValue
 */
public RightInsertTextField(String defaultValue) {
    super("", defaultValue);
}

public void paint(Graphics g) {
    String txt = this.getText();
    // 1. (Optional) keeping a check on input length can help
    // minimize custom code needed to handle wrap-around text.
    if (txt.length() > this.getMaxCharInputLength() && this.getMaxCharInputLength() > 0) {
        txt = this.lastGoodTxtInputEntry;
        this.setText(txt);
    } else {
        this.lastGoodTxtInputEntry = txt;
    }

    // 2. get rid of the default cursor painting by coloring over it with
    // the same color as the background
    XYRect xy = g.getClippingRect();
    g.setBackgroundColor(Color.WHITE);
    g.fillRect(xy.x, xy.y, xy.width, xy.height);
    g.clear();

    // 3. Align text to the right.

    g.setColor(Color.BLACK);
    g.drawText(txt, 0, 0, (DrawStyle.RIGHT + DrawStyle.ELLIPSIS), getWidth());

}

/**
 * Look out for 'ENTER' being pressed.
 */
public boolean keyChar(char key, int status, int time) {
    // Prevent new lines in input field.
    if (Characters.ENTER == key) {
        if (this.nextFieldForFocus != null) {
            this.nextFieldForFocus.setFocus();
        }
        return true;
    } else {
        return super.keyChar(key, status, time);
    }
}

public void setMaxCharInputLength(int maxCharInputLength) {
    this.maxCharInputLength = maxCharInputLength;
}

public int getMaxCharInputLength() {
    return maxCharInputLength;
}

/**
 * @param nextFieldForFocus
 *            the nextFieldForFocus to set if 'ENTER' is pressed.
 */
public void setNextFieldForFocus(Field nextFieldForFocus) {
    this.nextFieldForFocus = nextFieldForFocus;
}

}

这里有一种方法:

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.BasicEditField;

public class RightInsertTextField extends BasicEditField {
    private String lastGoodTxtInputEntry = null;
    private int maxCharInputLength = 20;
    private Field nextFieldForFocus = null;

/**
 * Basic constructor.
 * 
 * @param defaultValue
 */
public RightInsertTextField(String defaultValue) {
    super("", defaultValue);
}

public void paint(Graphics g) {
    String txt = this.getText();
    // 1. (Optional) keeping a check on input length can help
    // minimize custom code needed to handle wrap-around text.
    if (txt.length() > this.getMaxCharInputLength() && this.getMaxCharInputLength() > 0) {
        txt = this.lastGoodTxtInputEntry;
        this.setText(txt);
    } else {
        this.lastGoodTxtInputEntry = txt;
    }

    // 2. get rid of the default cursor painting by coloring over it with
    // the same color as the background
    XYRect xy = g.getClippingRect();
    g.setBackgroundColor(Color.WHITE);
    g.fillRect(xy.x, xy.y, xy.width, xy.height);
    g.clear();

    // 3. Align text to the right.

    g.setColor(Color.BLACK);
    g.drawText(txt, 0, 0, (DrawStyle.RIGHT + DrawStyle.ELLIPSIS), getWidth());

}

/**
 * Look out for 'ENTER' being pressed.
 */
public boolean keyChar(char key, int status, int time) {
    // Prevent new lines in input field.
    if (Characters.ENTER == key) {
        if (this.nextFieldForFocus != null) {
            this.nextFieldForFocus.setFocus();
        }
        return true;
    } else {
        return super.keyChar(key, status, time);
    }
}

public void setMaxCharInputLength(int maxCharInputLength) {
    this.maxCharInputLength = maxCharInputLength;
}

public int getMaxCharInputLength() {
    return maxCharInputLength;
}

/**
 * @param nextFieldForFocus
 *            the nextFieldForFocus to set if 'ENTER' is pressed.
 */
public void setNextFieldForFocus(Field nextFieldForFocus) {
    this.nextFieldForFocus = nextFieldForFocus;
}

}
这会有帮助的

editField = new EditField("", "", maxChars, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE){
    private String text = "";
    protected boolean keyChar(char key, int status, int time){
        switch (key){
            case Characters.BACKSPACE:{
                try {
                    text = text.substring(0,text.length()-1);
                    invalidate();
                } catch (IndexOutOfBoundsException e) {}
                return true;
            }
        }
        text = text + key;
        invalidate();
        return true;
    }
    protected void paint(Graphics graphics) {
        graphics.drawText(text,0, 0, DrawStyle.RIGHT, width - 10);
        super.paint(graphics);
    }
};
这会有帮助的

editField = new EditField("", "", maxChars, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE){
    private String text = "";
    protected boolean keyChar(char key, int status, int time){
        switch (key){
            case Characters.BACKSPACE:{
                try {
                    text = text.substring(0,text.length()-1);
                    invalidate();
                } catch (IndexOutOfBoundsException e) {}
                return true;
            }
        }
        text = text + key;
        invalidate();
        return true;
    }
    protected void paint(Graphics graphics) {
        graphics.drawText(text,0, 0, DrawStyle.RIGHT, width - 10);
        super.paint(graphics);
    }
};

你试过了吗?我怀疑它只会把字段本身放到右边,而不会把里面的字符放到右边。你试过了吗?我怀疑它只会把字段本身放在右边,而不会把里面的字符放在右边@AlexanderFarber这有一个很好的优点,就是在使用Enter时将焦点向下移动。@clafonta我会使用BasicEditField.setMaxSizeint maxSize来处理最大字段大小,而不必自己做。然而,这只是一个风格问题——我只是为了向其他读者完整地介绍它@AlexanderFarber这有一个很好的优点,就是在使用Enter时将焦点向下移动。@clafonta我会使用BasicEditField.setMaxSizeint maxSize来处理最大字段大小,而不必自己做。然而,这只是一个风格问题——我只是为了向其他读者完整地介绍它。