简体   繁体   English

使用asynctask更新GridView

[英]Updating GridView with asynctask

I have read in many places that you can't access a gridview from outside the ui thread, but I believe that's what is causing the problem of my gridview taking long to load. 我在很多地方都读到无法从ui线程外部访问gridview,但是我相信这就是导致我的gridview加载时间很长的问题。 I have it with 75 images and it makes the ui hang so it looks like my app is frozen. 我有75张图像,它使ui挂起,因此看起来我的应用程序已冻结。 Is there a way to use async task to load the images into the grid view off the ui thread? 有没有一种方法可以使用异步任务将图像从ui线程加载到网格视图中? or is there a different way to accomplish this? 还是有其他方法可以做到这一点?

You should to consider lazy loader for the images. 您应该为图像考虑延迟加载程序。

I suggest you that you change the approach: Display all data except images immediately, then load images with lazy loader. 我建议您更改方法:立即显示除图像以外的所有数据,然后使用惰性加载器加载图像。 You can even implement image cache if the images are repeated. 如果图像重复,您甚至可以实现图像缓存。

That approach will increase speed of your UI and then it doesn't like that app is frozen. 这种方法将提高用户界面的速度,然后又不像该应用程序被冻结一样。

As Bosko mentioned, you need to "lazy" load your images off the main UI thread. 正如Bosko所述,您需要从主UI线程“延迟”加载图像。 I find a great way to take away all the pain of doing this is to use a library like Picasso which makes it dead simple. 我发现摆脱这种痛苦的一种好方法是使用像Picasso这样的库,这使它变得非常简单。 It handles all of pitfalls you will encounter if you try to create a lazy loader yourself. 如果您尝试自己创建一个惰性加载程序,它将处理您将遇到的所有陷阱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM