android - Add data fromEeditText to double -
i have app user can enter amount edittext want able add or subtract to/from double able display double textview within activity.
i'm not sure how go , appreciate help. in advance!
edit: forgot mention want data kept between app launches/closes.
in activity accepts input edittext
:
double value = double.parsedouble(youredittext.gettext().tostring()); sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); if (adding) { value = prefs.getfloat("your.float.key", 0f) + value; } else { value = prefs.getfloat("your.float.key", 0f) - value; } sharedpreferences.editor editor = prefs.edit(); editor.putfloat("your.float.key", value); editor.apply();
in activity shows value:
sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); double value = prefs.getfloat("your.float.key", 0f); yourtextview.settext(value.tostring());
Comments
Post a Comment