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

后端 未结 3 1598
梦毁少年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:21

    Add a KeyListener to the textbox that listens key events. Within the key event, listen to the "ENTER" key pressed and perform your action.

    You can find something similar here: Android Development: How To Use onKeyUp? and in the docs for UI-Events.

    A good example is in the linked SO question. Following this, you should get the desired result.

提交回复
热议问题