浏览文件值进行求和

发布于 2024-11-29 00:51:57 字数 231 浏览 1 评论 0原文

我有一个活动将一些数据存储到文件中,并且该文件的数据显示在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沩ん囻菔务 2024-12-06 00:51:57

您的最后一条评论表明您已经找到了解决方案,因此我怀疑这比我们收到的更多。

尝试猜测,您的意思是:
- 您将数据(您可能知道,基于某些用户输入)存储在文件中,但在每次运行应用程序期间保留该文件;也就是说,它是每次运行应用程序时都会增长的某种日志文件
- 您想在启动应用程序时显示所支付价格的总和,但您不想解析整个文件,因此您更愿意将其存储在其他地方?

如果是这样,您可能希望将该特定金额存储在其他地方(一些 共享首选项 命名为“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文