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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -