TextWatcher的事件被调用两次

Jay*_*jar 12 android textwatcher

在我的应用程序中,我将TextWatcher放在EditText上.当我更改EditText的文本时,TextWatcher的事件被调用两次.

我正在使用模拟器来运行应用程序.

Ste*_*ike 10

你的代码是怎么样的?这是TextWatcher的正常行为.例:

myInput.addTextChangedListener(new TextWatcher() {
        boolean mToggle = false;

        public void onTextChanged(CharSequence cs, int s, int b, int c) {}

        public void afterTextChanged(Editable editable) {
            if (mToggle) { 
                Toast.makeText(getBaseContext(), "HIT KEY",Toast.LENGTH_LONG).show();
            }
            mToggle = !mToggle;
        }

        public void beforeTextChanged(CharSequence cs, int i, int j, int k) {}
    });
Run Code Online (Sandbox Code Playgroud)