2

I am testing the imeOption feature in Android EditText. I understand how it works and the various options like Go, Search, Done etc. My question relates to its event listener.

Take this answer, for example, the setOnEditorActionListener gets invoked when the right corner button on the soft keyboard is clicked.

The setOnEditorActionListener will get invoked regardless (if I'm right) of what time option is specified (as long as there is one); then why bother checking what action it was? Won't an Edit text have a fixed time option specified in the xml layout? I don't understand when setOnEditorActionListener gets invoked why does everyone check action id ?

Community
  • 1
  • 1
Jake
  • 16,329
  • 50
  • 126
  • 202

1 Answers1

0

I have a possible reasoning why Android provides action id in the setOnEditorActionListener event. I think its because the action associated with an EditText can be changed at runtime. I tried a simple test:

  1. Set imeOptions to actionSend
  2. In the event, switched the action to using: setImeActionLabel("search", EditorInfo.IME_ACTION_SEARCH)
  3. Navigated away from EditText and then back to it
  4. The soft keyboard now displayed "search" instead of send icon

If anyone has any other reasoning, please share.

Jake
  • 16,329
  • 50
  • 126
  • 202