1

how to know when I press the delete key from the soft keyboard in android, an event the content of the edittext is empty. I know when the content is not empty, can use TextChangeListener. Only the empty content how to listen the pressed key.

Samir Bhatt
  • 3,041
  • 2
  • 25
  • 39
dndxxiangyu
  • 29
  • 1
  • 3
  • 1
    Possible duplicate of [How to listen the keypress in the soft keyboard?](https://stackoverflow.com/questions/10616567/how-to-listen-the-keypress-in-the-soft-keyboard) – AskNilesh Nov 03 '17 at 07:08
  • Use setOnKeyListener for this – Samir Bhatt Nov 03 '17 at 07:11
  • setListener is not worked in same android system. Finally I got a smart idea, which can use a space replace by ImageSpan,and set picture size is 0*0. So there always will not be empty. – dndxxiangyu Dec 21 '17 at 09:32

2 Answers2

-1

KeyEvent provides keyboard events

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // Do Code here
        }
        return super.onKeyDown(keyCode, event);
    }
rajahsekar
  • 916
  • 1
  • 11
  • 25
-1

setListener is not worked in same android system. Finally I got a smart idea, which can use a space replace by ImageSpan,and set picture size is 0*0. So there always will not be empty.

dndxxiangyu
  • 29
  • 1
  • 3