events - Android: Numeric key register backspace pressed -
i have edittext accepts numeric numbers defined this:
<edittext android:id="@+id/routeinit_price" android:layout_height="wrap_content" android:layout_width="120dp" android:layout_gravity="center_horizontal" android:lines="1" android:inputtype="numberdecimal"/>
i validating if there valid input below enable/disable button. however, doesn't receive event on backspace/delete button pressed event. how can fix that? because when edittext empty button should diabled.
edittext pricefield = (edittext)findviewbyid(r.id.routeinit_price); pricefield.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view view, int keycode, keyevent keyevent) { if(keyevent.getaction() == keyevent.action_up) { if(((edittext)view).gettext().tostring().length() > 0) ready.setenabled(true); else ready.setenabled(false); } return false; } });
try
pricefield.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { if(pricefield.gettext().tostring().length() > 0) ready.setenabled(true); else ready.setenabled(false); } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { } });
Comments
Post a Comment