android - onKey event for editText not firing -


i'm having hard time getting onkey event trigger on edittext view. i've been googling on hour , seems says have add onkeylistener view it's not triggering it. tried adding entire activity , tried adding view neither way triggering function.

my code:

xml:

 <edittext        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:id="@+id/interests_edittext" /> 

java:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.add_post);      interests_edittext = (edittext) findviewbyid(r.id.interests_edittext);     interests_edittext.setonkeylistener(new onkeylistener(){                 public boolean onkey(    view view,    int keycode,    keyevent event){                    log.i("debug","test");                    if (keycode == keyevent.keycode_enter) {                         return true;                    }                    else {                        return false;                    }                }            }     ); 

update: final goal recognize when press space while in edittext view. added xml

android:inputtype="text" 

and changed code

public boolean onkey(    view view,    int keycode,    keyevent event){                    log.i("debug","outside");                    if (keycode == keyevent.keycode_space) {                        log.i("debug","space");                        return true;                    }                    else {                        return false;                    } 

now keyboard shows next button when pressed logs "outside" doesn't log "space"

do wanna capture enter event? if so, try setoneditoractionlistener

for update info: capture space key, try addtextchangedlistener


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -