I need to format the string entered by the user on a EditField.
This is my code:
input = new BorderedEditField(20, BasicEditField.FILTER_NUMERIC);
input.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
input.setText(pruebaTexto(input.getText()));
}
});
public static String pruebaTexto(String r){
return r+"0";
}
But it ends on a stackoverflow error caused apparently because of an infinite loop.
What is wrong with the code?
You can prevent the recursion by checking whether this is an internal update.
For Blackberry, this is done by checking the value of
contextThis is a non-Blackberry-specific solution that will work for any variety of listener: