android - How to Change String to a Double? -
i have created small program allows users enter numeric values edittext.
- when click button first time, app should display in textview
- after should save new value if greater previous value
help me please.
public class bidactivity extends activity implements onclicklistener { public textview tt; public edittext textbo; public string total; public button btnnn; public double protein; double price = 0; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); textbo = (edittext)findviewbyid(r.id.txtbid); tt = (textview)findviewbyid(r.id.textview1); btnnn = (button)findviewbyid(r.id.btnbit); btnnn.setonclicklistener(this); } @override public void onclick(view v) { // todo auto-generated method stub string total = textbo.gettext().tostring(); price = double.parsedouble(textbo.gettext().tostring()); //tt.settext("double: "+price); if(double.parsedouble(textbo.gettext().tostring()) < price){ tt.settext("double: "+price); }else{ tt.settext("double: "+double.parsedouble(textbo.gettext().tostring())); } } }
i'm guessing trying this:
double price = 0; double savedprice = 0.0; ... @override public void onclick(view v) { price = double.parsedouble(textbo.gettext().tostring()); if(savedprice < price){ tt.settext("double: "+price); savedprice = price; } // otherwise leave tt }
Comments
Post a Comment