我该如何更新进度的状态GridView控件/ ListView中的每一个元素? [英] How do I update the state of a ProgressBar on every element of a GridView / ListView?

查看:105
本文介绍了我该如何更新进度的状态GridView控件/ ListView中的每一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个GridView,每一个元素应该有一个单独的进度。这些元素重新present单独的下载,我想显示使用这些ProgressBars下载量的状态。

Currently I have a GridView, and every element should have a separate ProgressBar. The elements represent separate downloads, and I'd like to show the state of the downloads using these ProgressBars.

不过,我应该怎么升级呢?我的问题是,根据文档(和我所听到的谷歌IO视频),更新AdapterViews元素的唯一办法是更新指定的适配器,每次更新后调用.notifyDatasetChanged()。

But how should I update them? My problem is, that according to the docs (and what I've heard on the Google IO videos), the only way to update elements in AdapterViews is to update the assigned adapter, and call .notifyDatasetChanged() after every update.

当然,这也实际上在这种情况下工作过,但更新相当频繁(5-10更新秒)。而在这个频率呼叫.notifyDatasetChanged中断与GridView的任何干预。例如。在网格中的项目的用户尝试长点击,但是点击事件停止,因为一个.notifyDatasetChanged被称为更新下载的进度。

Of course this does actually work in this case too, but the updates are quite frequent (5-10 updates sec). And calling .notifyDatasetChanged in this frequency breaks any interaction with the GridView. E.g. the user tries to long-click on an item in the Grid, but the clicking event stops, because a .notifyDatasetChanged was called to update the progress of a download.

是否有任何其他方式做到这一点?我应该沟AdapterViews和使用其他什么东西?

Is there any other way to do this? Should I ditch AdapterViews and use something else?

推荐答案

对于像你这样的情况下,有许多频繁的更新(多次秒),notifyDatasetChanged是不正确的方式去 - 你需要直接更新个人意见

For situations like yours with many frequent updates (many times a second), notifyDatasetChanged isn't the right way to go - You need to update the individual views directly.

没有看到你的code和文件下载,并在GridView中的条目之间的关系,很难说究竟什么叫你需要,但是:

Without seeing your code and the relationship between a file download and an entry in the GridView, it's hard to say exactly what calls you'll need, but:

-GridView有一个getChildAt,你可以用它来抓住一个视图在一个特定的指数。
- 存在就是在更新视图,如果它甚至没有明显的没有意义的。如果不是getFirstVisiblePosition()和getLastVisiblePosition()之间,不理它,它会得到绘制时,它被重新绘制。

-GridView has a "getChildAt" you can use to grab a view at a specific index.
-There's no point in updating the view if it's not even visible. If it's not between getFirstVisiblePosition() and getLastVisiblePosition(), ignore it, it'll get drawn with updated data whenever it gets redrawn.

这篇关于我该如何更新进度的状态GridView控件/ ListView中的每一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆