我在这样的 EditText 上有一个 TextWatcher
// the text changed listener for the search field
private TextWatcher searchWatcher = new TextWatcher()
{
@Override
public void afterTextChanged(Editable span)
{
Log.v(TAG, "afterTextChanged: "+etSearch.getText().toString());
}
@Override
public void beforeTextChanged(CharSequence s,
int start,
int count,
int after)
{
Log.v(TAG, "beforeTextChanged: "+etSearch.getText().toString()
+"; start="+start+"; count="+count+"; after="+after);
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
Log.v(TAG, "onTextChanged: "+etSearch.getText().toString());
}
}
(其中 etSearch 是我的 Edittext etSearch.addTextChangedListener(searchWatcher)
。)
我有一个运行 2.1-update1 的索尼爱立信 Xperia 和一个也运行 2.1-update1 的 AVD。在模拟器中,我单击 EditText,使用软键盘输入 abc,然后按一次 del 按钮。在电话上,我触摸 EditText,在软键盘上键入 abc,然后按一次 del。在电话中,我得到了这个:
beforeTextChanged: ; start=0; count=0; after=1
onTextChanged: a
afterTextChanged: a
beforeTextChanged: a; start=0; count=1; after=2
onTextChanged: ab
afterTextChanged: ab
beforeTextChanged: ab; start=0; count=2; after=3
onTextChanged: abc
afterTextChanged: abc
beforeTextChanged: abc; start=0; count=3; after=2
onTextChanged: ab
afterTextChanged: ab
在模拟器上,我得到了这个:
beforeTextChanged: ; start=0; count=0; after=1
onTextChanged: a
afterTextChanged: a
beforeTextChanged: a; start=1; count=0; after=1
onTextChanged: ab
afterTextChanged: ab
beforeTextChanged: ab; start=2; count=0; after=1
onTextChanged: abc
afterTextChanged: abc
beforeTextChanged: abc; start=2; count=1; after=0
onTextChanged: ab
afterTextChanged: ab
为什么他们不一样?哪一个是正确的行为?