如何申请上的EditText的Textchange事件事件、EditText、Textchange

2023-09-04 13:22:06 作者:爱上是我的错

我开发了简单的应用程序,像减法,加法。 在这个应用程序,我用三个EditTexts,一为答案,另外两个为问题。 我想计算的文本改变事件问题的答案。但是,当我申请的文字改变事件双方的这种情况发生的事件,但无法正常工作。因为当我在第一个问题中的EditText文本输入事件发生,但它引发此异常:

  07-03 16:39:48.844:E / EduApp日志:=>(12537):错误在文本改变事件java.lang.NumberFormatException:无法解析''作为整
 

我该怎么办? 我用的是 TextWatcher 文本更改事件。

  txtOne.addTextChangedListener(本);
txtTwo.addTextChangedListener(本);

公共无效afterTextChanged(编辑S){}

公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,之后INT){}

公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){}
 

解决方案

我觉得你收到空字符串这是造成这个问题。确保你从你的EDITTEXT得到一个非空字符串。

考虑您的EDITTEXT没有输入任何价值,你想获得它的价值,并转换成INT你会遇到这样那样的问题。

  edittext.addTextChangedListener(新TextWatcher(){

    公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,
            诠释计数){
        如果(!s.equals())
                {//做你的工作在这里}
        }

    }

    公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,
            之后INT){

    }

    公共无效afterTextChanged(编辑S){

    }
});
 
uniapp 空格怎么打 uni app 坑

另外,请检查该链接了解更多的想法,

http://stackoverflow.com/a/3377648/603744

I developed one simple app, like subtraction, addition. In this app I use three EditTexts, one for answer and other two for question. I want to calculate the answer of question on text change event. But when I apply the text change event on both of this the event occur but not properly work. Because when I enter in the text in first EditText of question the event occur but it throws this exception:

07-03 16:39:48.844: E/EduApp Log :=>(12537): Error In Text change Event java.lang.NumberFormatException: unable to parse '' as integer

What do I do? I use the TextWatcher for text change event.

txtOne.addTextChangedListener(this);
txtTwo.addTextChangedListener(this);

public void afterTextChanged(Editable s) {}

public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

public void onTextChanged(CharSequence s, int start, int before, int count) {}  

解决方案

I think you are receiving empty String " " which is causing this problem. Make sure you get a non empty String from your Edittext.

Consider your Edittext doesn't have any value typed in, and you are trying to get its value and convert into int you will run into this kind of problem.

   edittext.addTextChangedListener(new TextWatcher() {

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        if(!s.equals("") )
                { //do your work here }
        }

    }

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {

    }

    public void afterTextChanged(Editable s) {

    }
});

Also check this link for more idea,

http://stackoverflow.com/a/3377648/603744