Change EditText text from onTextChangeListener()

前端 未结 2 323
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 18:10

I am working on an Android application.In my app I have to use images based on the text.So I write OnChangeListener() for EditText.The following is

2条回答
  •  抹茶落季
    2021-01-13 18:26

    One more solution can be to use boolean variable, so that it doesn't get into infinite callstack and eventually giving stackoverflow exception

    public void afterTextChanged(Editable s) {
        if(!flag) 
        {
                flag = true;
    
                edt.setText("string");
    
                flag = false;
        }
    }
    

提交回复
热议问题