IME_ACTION_DONE seems to destroy the View.OnKeyListener on Android

234 views Asked by At

I have a EditText view on my RelativeLayout, and I can capture the soft input keyboard keycode KEYCODE_ENTER (int 66). This is the Key listener:

myedittext.setOnKeyListener(new View.OnKeyListener() 
  {
    @Override 
    public boolean onKey(View v, int keyCode, KeyEvent event)
     {
       Log.d("softinput", "key received!");
     }
  });

The problem is that the soft keyboard displays the key labeled "Next" and I need it to display "Done". When i (successfully) change the key to "Done" using the API:

myedittext.setImeOptions(EditorInfo.IME_ACTION_DONE);

The Key listener stops working and i can no longer receive anything in the key listener. The LogCat doesnt show anything. It literally stops working. When i remove the above line of code, everything works again but the key displays "Next".

I was guessing this was clearing some other flag required for it to notify keys, but using EditorInfo.IME_ACTION_NEXT works perfect, but the soft key, of course displays "Next".

Anybody knows a workaround for this? or the reasons why this happens?

Thanks.

2

There are 2 answers

1
Mauricio Silva On

You say you have an EditText, but your variable is "mytextview". Are you setting the key listener correctly to the EditText ?

1
Shalev Keren On

Change imeOptions to action done in XML rather than in code. Add the following to the edittext tag,

android:imeOptions="actionDone"