How do I trigger an action when the user has hit enter?

后端 未结 3 1597
梦毁少年i
梦毁少年i 2021-01-18 05:40

If (in Android) I have an EditText box, how can I trigger an event when the user has finished entering data and hits return/Next?

I have tried using the code below b

3条回答
  •  离开以前
    2021-01-18 06:22

    I played around a bit with various things and found that the code below works:

    myEditText.setOnEditorActionListener(new OnEditorActionListener() {                     
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // Do some stuff
        }
    });
    

提交回复
热议问题