How to update the same EditText using TextWatcher?

前端 未结 4 918
故里飘歌
故里飘歌 2020-12-11 19:30

In my Android application I need to implement a TextWatcher interface to implement onTextChanged. The problem I have is, I want to update the same EditText With

4条回答
  •  孤城傲影
    2020-12-11 19:54

    late answer, if someone looking this is how i did it.

    • set addTextChangedListener initially
    • in one of the call back (say onTextChanged()) remove addTextChangedListener
    • Still interested in receiving updates add it back again.

    here is the code.

    editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                Log.d("log", "before");
            }
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                Log.d("log", "after");
                editText.removeTextChangedListener(this);
    
                ediText.setText("text you wanted to put");
    
                editText.addTextChangedListener(this);
    
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
    
            }
        });
    

提交回复
热议问题