本文介绍了同时,从文本文件中读取记录的Andr​​oid更新进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到在从存储在内部存储的文本文件中的记录读取,更新进度条的最佳方式。在我的活动片段我用一个按钮加载进度以进度条进行更新对话框。

I am trying to find the best way to update a Progress Bar while reading in records from a text file stored on internal storage. In my activity fragment I use a button to load a progress dialog with a progress bar to be updated.

问题是如果一个文本文件中有超过2000+记录(每行1记录),我应该算之前在文本文件中的行数来装载记录,并使用这个值来估算完成百分比为进度条?或是否有这样做的更优雅的方式?

The problem is if a the text file has over 2000+ records (1 record per line) should I count the number of lines in the text file prior to loading the records, and use this value to estimate the percentage complete for the Progress Bar? or Is there a more elegant way of doing this?

推荐答案

进度条的准确性并不重要,并积极回应这是更重要的。我只是抓住了文件的大小和读取的字节/文件大小更新进度条。读取整个文件要弄清楚它的记录计数可能是非常昂贵的,它不会得到你了。

The accuracy for the progress bar isn't critical, and it's more important to be responsive. I'd just grab the file's size and update the progress bar as bytes read/file size. Reading the entire file to figure out its record count could be prohibitively expensive, and it won't gain you much.

这篇关于同时,从文本文件中读取记录的Andr​​oid更新进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:40