java - NumberFormatException: Invalid int "-" -
java - NumberFormatException: Invalid int "-" -
i have problem. have edittext has android:inputtype="numberdecimal|numbersigned"
. in java code have this
@override public void ontextchanged(charsequence arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub int value = 0; string editcontent = edittext.gettext().tostring(); if(editcontent != null && editcontent.length() > 0) { value = integer.parseint(editcontent); } seekbar.setprogress(value); }
when seek insert negative number have numberformatexception invalid int "-". how can solve this?
first time when set "-", method ontextchanged
called, , parsing done on "-", not valid int. need escape parsing if string "-".
use below code ontextchanged(...)
. better move code aftertextchanged(...)
int value = 0; if (! textutils.isempty(arg0)) { string text = arg0.tostring(); if ("-".equals(text)) { // nil } else { value = integer.parseint(text); } seekbar.setprogress(value); }
java android xml
Comments
Post a Comment