TextWatcher events are being fired multiple times

后端 未结 7 2107
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 12:57

I have an annoying problem with TextWatcher. i\'ve been searching the web but couldnt find anything. appreciate if someone could assist me.

For some reason t

7条回答
  •  独厮守ぢ
    2020-12-05 13:25

    For me the below code worked. Please observe that boolean value has been changed after if condition loop in afterTextChanged method

            edittext.addTextChangedListener(new TextWatcher() 
            {
                boolean considerChange = false;
    
                public void beforeTextChanged(CharSequence cs, int start, int count, int after) {}
    
                public void onTextChanged(CharSequence cs, int start, int before, int count) {}
    
                public void afterTextChanged(Editable editable) 
                {
                    if (considerChange) 
                    { 
                        // your code here
                    }
                    considerChange = !considerChange; //see that boolean value is being changed after if loop
                }
    
    
            });
    

提交回复
热议问题