本文介绍了TextWatcher的事件被两次调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

On my application I put TextWatcher on EditText. When I change the text of the EditText, the events of TextWatcher are being called twice.

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

I am using emulator for running the app.

推荐答案

您的代码看起来如何?这是TextWatcher的正常行为.示例:

How does your code looks like? that is the normal behaviour of TextWatcher.Example:

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) {}
    });

这篇关于TextWatcher的事件被两次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 16:57