ProgressDialog 中的进度单元
Android 的 ProgressDialog 允许您将当前进度和最大值设置为整数。这些值在对话框中显示如下:
3401/10023
其中第一个数字是当前进度,第二个数字是最大值。
我还想显示测量单位。像这样的事情:
3401/10023 知识库
使用 ProgressDialog 可以实现这一点吗?如果没有,您建议如何向用户提供此信息?我试图避免重新实现 ProgressDialog 只是为了包含该单元。
Android's ProgressDialog allows you to set the current progress and maximum value as integers. These values are shown in the dialog like this:
3401/10023
Where the first number is the current progress, and the second number is the maximum value.
I would like to also show the unit of measurement. Something like this:
3401/10023 KB
Is this possible using ProgressDialog? If not, what do you recommend doing to give this information to the user? I'm trying to avoid reimplementing ProgressDialog just to include the unit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更新:
setProgressNumberFormat
自 11 级起成为 API 的一部分。HEAD 的
ProgressDialog
源代码已经包含一个名为的公共函数setProgressNumberFormat
可用于设置单位。不幸的是这个功能在最新的Android版本中似乎还没有提供。我想它将包含在未来的更新中。同时,复制
ProgressDialog
的实现是最好的选择。子类化ProgressDialog
是没有用的,因为它的所有成员都是私有的,并且使用view.findViewById(R.id.progress_number)
来获取TextView
直接极大有风险,因为没有什么可以确保 id 始终相同(或者TextView
始终存在)。Update:
setProgressNumberFormat
is part of the API since level 11.The HEAD of the
ProgressDialog
source code already includes a public function calledsetProgressNumberFormat
which can be used to set the unit. Unfortunately this function does not seem to be available in the latest Android version. I guess it will be included in a future update.In the meantime, copying this implementation of
ProgressDialog
is the best option. SubclassingProgressDialog
is of no use because all of its members are private and working withview.findViewById(R.id.progress_number)
to get theTextView
directly is extremely risky, as nothing ensures that the id will be always the same (or that theTextView
will always exist).从API 11开始,您可以调用以下函数来达到您的目的。
Starting from API 11, you can call the following function to achieve your purpose.
在 ProgressDialog 源文件中:
您必须重新实现它,您无法避免它
In the ProgressDialog source file :
You must reimplement it, you cannot avoid it
对我来说,我可以设置并不明显:
也许这种最简单方式对其他人来说并不明显......
It wasn't obvious for me that I can just set:
Maybe this simplest way isn't obvious for somebody else...