Gridview getChildAt hidden fields

淺唱寂寞╮ 提交于 2019-12-11 10:16:47

问题


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


回答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.



来源:https://stackoverflow.com/questions/6243148/gridview-getchildat-hidden-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!