简体   繁体   中英

Browse a file values to make a sum

I have an activity that stores some data to a file and this file's data is displayed on a ListView. If i want to make the sum of a value, how can i do it? By manipulating the file? Here is the data stored in the file:

data_vidange = date + ": " + km + "km" + " " + prix + "dt "+ " "+ "\n";

i want to make the sum of prix values. Is that possible? Thank you very much.

Your last comment suggests you have a solution, so I suspect there's more to this than we received.

Attempting a guess, do you mean that: - you store data (which you know, based on some user input probably) in the file, but you keep the file during each run of the application; that is, it's some kind of log file growing each time you run the application - you would like to display the sum of the price paid when you start the application, but you don't want to parse the whole file so you'd prefer to store it elsewhere?

If so, you may want to store that particular sum somewhere else (some shared preference named "prixTotal" or something), so that you can access it when you (re)start the application. Of course you'll need to be careful that the sum is always accurate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM