Android 三星Galaxy Note 2从EditText中删除文本
我有一个EditText,上面附加了一个TextWatcher。每次更改后,内容都会从特殊字符中删除,例如Android 三星Galaxy Note 2从EditText中删除文本,android,android-edittext,selection,galaxy,Android,Android Edittext,Selection,Galaxy,我有一个EditText,上面附加了一个TextWatcher。每次更改后,内容都会从特殊字符中删除,例如ë和ä。我将结果放回可编辑窗口,显示在UI上。除三星Galaxy Note 2外,它在所有设备上都能正常工作 因此,在注释上发生的是,第一个字符被接受并显示。输入第二个字符后,onTextChanged和beforeTextChanged都给出了s.length()的0 如果您注释掉Selection.setSelection(信息、位置)它工作,但它将光标设置在开始处 文本观察者 ed
ë
和ä
。我将结果放回可编辑窗口,显示在UI上。除三星Galaxy Note 2外,它在所有设备上都能正常工作
因此,在注释上发生的是,第一个字符被接受并显示。输入第二个字符后,onTextChanged
和beforeTextChanged
都给出了s.length()
的0
如果您注释掉Selection.setSelection(信息、位置)代码>它工作,但它将光标设置在开始处
文本观察者
editTextWatcher = 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 s)
{
// Prevent a stackoverflow
editText.removeTextChangedListener(this);
editText.setText(cleanDescription(s.toString()));
editText.addTextChangedListener(this);
editText.requestFocus();
int position = editText.length();
Editable info = editText.getText();
// Set the cursor at the end
Selection.setSelection(info, position);
}
};
清洁功能
private String cleanDescription(String info)
{
Log.d(TAG, "cleanDescription()");
if (info != null)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
{
info = Normalizer.normalize(info, Normalizer.Form.NFD);
}
info = info.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
info = info.replaceAll("[^a-zA-Z0-9\\s.,-]", "");
}
return info;
}
Logcat会发出警告
09-23 16:22:24.865: W/IInputConnectionWrapper(5086): setComposingText on inactive InputConnection
09-23 16:22:24.865: W/IInputConnectionWrapper(5086): getExtractedText on inactive InputConnection
09-23 16:22:24.870: W/IInputConnectionWrapper(5086): finishComposingText on inactive InputConnection