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:
using
edittext.addtextchangedlistener(new textwatcher()..
result: "\n" character either in ontextchanged , aftertextchanged
callbacks. "remove" character , send chat, don't like
way.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
Post a Comment