kehnar
kehnar

Reputation: 1387

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 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

Upvotes: 0

Views: 386

Answers (1)

Vit Khudenko
Vit Khudenko

Reputation: 28418

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

Upvotes: 1

Related Questions