TextWatcher事件被解雇多次 [英] TextWatcher events are being fired multiple times
问题描述
我有一个恼人的问题与TextWatcher。我一直在寻找的网站,但无法找到任何东西。 AP preciate如果有人可以帮助我。
I have an annoying problem with TextWatcher. i've been searching the web but couldnt find anything. appreciate if someone could assist me.
出于某种原因,调用TextWatcher事件的在一个文本的变化的是飘忽不定。有时它们被触发一次(如他们应该是),有时两次,有时3次。不知道为什么,整个事情是非常简单的。有时也对afterTextChanged()可编辑的参数返回的toString)长()为空值(和
For some reason the calls to the TextWatcher events upon one text change are erratic. sometimes they are being triggered once (like they should be), sometimes twice, and sometimes 3 times. have no idea why, the whole thing is very straight forward. also sometimes the Editable parameter on afterTextChanged() returns empty values in toString() and length().
code是如下:
private TextWatcher mSearchAddressTextChangeListener = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable searchedAddress) {
System.out.println("called multiple times.");
}
};
在 afterTextChanged()
(和的AsyncTask
)即时没有进行任何更改文本或的EditText
视图。
inside afterTextChanged()
(and the AsyncTask
) im not making any change to the text or the EditText
view.
我看到问事件被调用两次的,但具有事件即时触发更多(或更少)的两倍。
i saw the question asked in Events of textwatcher are called twice, but im having the events triggered more (or less) than twice.
反正,AP preciate任何帮助。
anyway, appreciate any help.
编辑:我删除afterTextChanged的内容()导致此问题的发生,甚至没有我的code。是什么使我相信这是一个错误。当一个空间字符输入一个普通字符之后(事件处理程序被触发两次),或在一个普通字符被删除后,空间字符(退格键,事件处理程序被触发3次)的错误是存在的。帮助仍将AP preciated。
I removed the content of afterTextChanged() cause this problem is happening even without my code. what leads me to believe this is a bug. The bug is occuring when a 'space' char is entered right after a regular char (event handlers are triggered twice) or when a 'space' char after a regular char is removed (backspace. event handlers are triggered 3 times). help will still be appreciated.
推荐答案
我有同样的问题,当我pressed退格键光标在一个连续的文本年底,afterTextChange被称为3次: - 第一次用正确的价值 - 第二次有明确的价值 - 第三次为正确的值再次
I had the same kind of problem, when I pressed backspace with cursor at the end of a continuous text, afterTextChange was called 3 times: - The first time with the correct s value - The second time with a clear value - The third time with the correct value again
在其搜索了很多在网络上,我试图改变我的EditText inputType到
After having search a lot on the web, I tried to change my EditText inputType to
android:inputType="textNoSuggestions"
不要问我为什么,但它的工作,afterTextChanged现在被称为一次。
Don't ask me why, but it worked, afterTextChanged is now called only once.
这篇关于TextWatcher事件被解雇多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!