android - Setting initial Edittext value to blank on focus -
i have 4 edit text fields in app take in 1 long , 3 double values respectively. have used them onfocuschangedlistener(). issue whenever edit text gains focus default (0.0 in case of double) displayed edit field before user enters values. want them to blank before user enters values. have tried using edittext.settext("") , edittext.sethint(""). these work when activity starts, once edit field gains focus default values shown. please me glitches. thank you.
heres code
public void onfocuschange(view edittextfocus , boolean hasfocus) { // todo auto-generated method stub try { km= long.parselong(etkm.gettext().tostring()); fuelqty= double.parsedouble(etfuelqty.gettext().tostring()); fuelprice= double.parsedouble(etfuelprice.gettext().tostring()); totalcost= double.parsedouble(ettotalcost.gettext().tostring()); } catch(numberformatexception ne) { ne.printstacktrace(); } if(ettotalcost.hasfocus()) { if((fuelqty!=0)&&(fuelprice!=0)) totalcost=fuelqty*fuelprice; ettotalcost.settext(new decimalformat("##.##").format(totalcost)); } else if(etfuelqty.hasfocus()) { etfuelqty.settext(""); if((fuelprice!=0)&&(totalcost!=0)) fuelqty= (int) (totalcost/fuelprice); etfuelqty.settext(string.valueof(fuelqty)); } else if(etfuelprice.hasfocus()) { etfuelprice.settext(""); if((fuelqty!=0)&&(totalcost!=0)) fuelprice=totalcost/fuelqty; etfuelprice.settext(string.valueof(fuelprice)); } }
try setting sethint() something.
a hint placeholder until person enters input, can put "fuel price".
Comments
Post a Comment