设置文本(数字)通过其setchangelistener编辑场 [英] set text(number) to Edit Field through its setchangelistener

查看:361
本文介绍了设置文本(数字)通过其setchangelistener编辑场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想接受编辑字段数量最多两个decimal.So我设置监听到它,然后我
我检查号码是否是两位小数以上,如果是多于两位小数那么我
截断后,再次尝试设置截number.But它显示出在这个地方interestRate.setText(文本)。我的code 104误差

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

推荐答案

看起来像你只需要使用一些条件检查,以免在一个无限循环获取:

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

这篇关于设置文本(数字)通过其setchangelistener编辑场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆