android - Enter Key Does not Work on Key Listner -


i'm using onkeylistner address 'enter' key pressed via soft keyboard on edit text. [android.]i want when user press enter key soft keyboard should perform action-->take input edit box , pass function process. here's code:

editbox.setonkeylistener(new view.onkeylistener() {              @override             public boolean onkey(view v, int keycode, keyevent event) {                 // todo auto-generated method stub                 if ((event.getaction() == keyevent.action_down) &&                         (keycode == keyevent.keycode_enter)) {                      // code action on key press                      input = editbox.gettext().tostring();                     if(mengine.init(input, getapplicationcontext()))                     {                                                          sharepref = getsharedpreferences("info",mode_private);                         edit = sharepref.edit();                         edit.putstring("editbox",input);                         edit.commit();                           //                    inputdialog.dismiss();                     }                     else                     {                         ............                      }                     inputdialog.dismiss();                       return true;                 }                 return false;             }         });      

it seems not working.kindly if i'm doing wrong.

set property in edittext

android:imeoptions="actiondone" android:imeactionlabel="enter" 

you can use setoneditoractionlistener here sample code..

editbox.setoneditoractionlistener(new oneditoractionlistener() {              @override             public boolean oneditoraction(textview v, int actionid,                     keyevent event) {                 if(actionid == 0 || actionid== editorinfo.ime_action_done)                 {                     //paste code here.                 }                 return false;             }          }); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -