如何确定我在“del”按钮中删除的最后一个字母?

时间:2016-08-15 02:32:53

标签: android eclipselink

在TextView中使用“del”按钮删除字母后。我想确定已删除的信件。

1 个答案:

答案 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或将其声明为全局,以便在侦听器中访问它。

相关问题