浏览文件值进行求和
我有一个活动将一些数据存储到文件中,并且该文件的数据显示在 ListView 上。如果我想求一个值的总和,我该怎么做?通过操纵文件? 这是文件中存储的数据:
data_vidange = date + ": " + km + "km" + " " + prix + "dt "+ " "+ "\n";
我想计算 prix
值的总和。这可能吗? 非常感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的最后一条评论表明您已经找到了解决方案,因此我怀疑这比我们收到的更多。
尝试猜测,您的意思是:
- 您将数据(您可能知道,基于某些用户输入)存储在文件中,但在每次运行应用程序期间保留该文件;也就是说,它是每次运行应用程序时都会增长的某种日志文件
- 您想在启动应用程序时显示所支付价格的总和,但您不想解析整个文件,因此您更愿意将其存储在其他地方?
如果是这样,您可能希望将该特定金额存储在其他地方(一些 共享首选项 命名为“prixTotal”或其他名称),以便您在(重新)启动应用程序时可以访问它。当然,您需要注意总和始终准确。
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.