我需要找出插入到 EditText 中的新字符是什么。实际上,我使用 TextChange Listener 来查找文本字段中新输入的字符。例如,如果我一个一个地输入“成功”这个词。我需要获得新输入的角色。如果我在 e 旁边插入 X,我需要检测那个 X 字符。
请提供最好的解决方案
最佳答案
我认为您必须在 edittext 上尝试使用 TextChangedListener 来控制文本输入
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtEdit = (EditText) findViewById(R.id.editText1);
viewText = (TextView) findViewById(R.id.text);
txtEdit.addTextChangedListener (new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.i("TC", "beforeTC " + s.toString() + " "
+ s.subSequence(start, start + count).toString());
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.i("TC", "onTC " + s.toString() + " "
+ s.subSequence(start, start + count).toString());
}
public void afterTextChanged(Editable s) {
Log.i("TC", "afterTC " + s.toString());
}
});
}
关于Android:Edittext::get Entered Character from the keyboard at any position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28407704/