在TextView中使用“del”按钮删除字母后。我想确定已删除的信件。
答案 0 :(得分:0)
使用 onEditorActionListener 查明用户是否按下了DEL键,然后获取当前光标位置的字符:
final EditText editText = new EditText(this);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if(keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL) {
char deletedCharacter = textView.getText().charAt(editText.getSelectionStart());
}
return false;
}
});
信息: 将您的editText对象设为final或将其声明为全局,以便在侦听器中访问它。