android - How to catch soft keyboard "ENTER" -


i'm developing chat app, , looking way catch enter pressed on soft keyboard during message editing (in edittext). aim send text directly. have implemented "send" button.

two attempts:

  1. using edittext.addtextchangedlistener(new textwatcher()..

    result: "\n" character either in ontextchanged , aftertextchanged
    callbacks. "remove" character , send chat, don't like
    way.

  2. using edittext.setoneditoractionlistener(new textview.oneditoractionlistener()..

    result: doesn't work.

any better solution?

try this;

edittext.setonkeylistener(new onkeylistener() {     public boolean onkey(view v, int keycode, keyevent event)     {         if (event.getaction() == keyevent.action_down)         {             switch (keycode)             {                 case keyevent.keycode_dpad_center:                 case keyevent.keycode_enter:                     //perform action                     return true;                 default:                     break;             }         }         return false;     } }); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -