开发者

set text(number) to Edit Field through its setchangelistener

Hi I want to accept number in edit field up to two decimal.So I am setting listener to it Then I am checking whether number is two decimal or more and if it is more than two decimal then i am truncating the number and again trying to set the truncated number.But it showing 104 开发者_Go百科error at this place interestRate.setText(text).My code is

interestRate=new EditField();
interestRate.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String text=interestRate.getText().toString();
code here--
interestRate.setText(text);
}
};

So my question is whether text can be set from its listener or not


Looks like you just need to use some condition check in order not to get in an infinite loop:

interestRate=new EditField();
interestRate.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        String text = interestRate.getText().toString();
        // code here to create a truncated text
        if (!truncated.equals(text)) {
            // next time we will not get here 
            // because truncated will be equal to text
            interestRate.setText(text);
        }
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜