Gridview getChildAt隐藏字段
我在 Android 中遇到 Gridview 问题。
语境 : 我有一个 gridview,其中包含下载的图像列表(大约 100 张图像)。
为了让用户更方便,加载第一个gridview,里面有100张图像,上面有一个加载标志。 之后,我启动一个 AsyncTask: 在onProgressUpdate =>;使用 gridview.getChildAt 更新图像 在 onPostExecute => 中使用下载的位图列表更改 gridview 的适配器
我的问题出在 onProgressUpdate 中。 当使用 getChildAt(position) 时,我意识到位置意味着项目在可见矩形中的位置。所以有两个问题: =>首先,隐藏的图像不会更新(这就是我在 PostExecute 中执行 setAdapter 的原因) =>其次,如果我在下载时滚动,它会忘记第一个图像,以及滚动时的一些其他问题,但很难用文字表达......
我的问题有点简单,但我在Android Reference中没有找到,之后也是谷歌搜索: - 如何通过其真实位置而不是可见位置来更新 gridview 中的视图?
多谢
I have issue with Gridview in Android.
Context :
I have a gridview, with a list of images downloaded (around 100 images).
To do it more convenient for user, a first gridview is load, with inside 100 images on which is a logo Loading.
After that, I start an AsyncTask that :
In onProgressUpdate => Update image with gridview.getChildAt
In onPostExecute => change adapter of gridview with the list of bitmaps downloaded
My issue is in onProgressUpdate.
When using getChildAt(position), I realized that position means position of the item in the visible rect. So there is two issues :
=> First, hidden images are not updated (it's why I'm doing an setAdapter in PostExecute)
=> Second, if I scroll while downloading, it forget the first images, and some other issues while scrolling, but difficult to express with word ...
My question is a little easy, but I didn't find in Android Reference, and also after Google searches :
- How is it possible to update a view in a gridview by its real position, and not by visible position ?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可见的视图不存在,因此您无法更新它们。只有当用户滚动到特定项目时,您才能更新支持模型以获得正确的信息。因此,您需要做的是检索图像并将它们保存在缓存(或模型本身)中,以便在渲染特定视图时可以访问。
但是,我建议无需检索用户尚未看到的任何图像。
Views that are not visible do not exist, so you can't update them. You can only update your backing model to have the correct information once the user scrolls to a particular item. So what you need to do is to retrieve the images and save them in a cache (or the model itself) that you can access when rendering a particular view.
However, I would suggest that there's no need to retrieve any images the user is not seeing yet.