如何使用延迟加载或异步任务列表视图 [英] how to use lazy load or async task in List View

查看:137
本文介绍了如何使用延迟加载或异步任务列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在我的应用程序,显示在用户设备中的所有已安装应用程序的视图的列表。它显示的名称和图标。列表视图需要很长时间来加载和用户界面是其时加载响应。我看到有懒加载和异步任务教程资源,但他们似乎都从互联网上获取的图像。我需要的是系统延迟加载图像(这是应用程序图标)。我不知道如何与异步任务做这一点。有人可以帮我懒负载或AsyncTask的应用程序图标。这是我的应用程序的一个非常重要的组成部分,我会深深AP preciate它。谢谢你。

I am making a list of view in my application that shows all installed applications in the users device. It shows the name and the icon. The list view takes very long to load and the UI is unresponsive while its loading. I have seen the resources that have lazy load and async task tutorials but they all seem to fetch images from the internet. I need to lazy load images that are in the system (which are the application icons). I dont know how to do this with async task either. Can someone please help me lazy load or asynctask application icons. This is a very essential part of my application and i would deeply appreciate it. Thanks.

推荐答案

所以我通常不提供意见,如果没有任何明确的尝试/ code,以示对,但我记得当我第一次面对与AsyncTasks和一般线程以及如何这是一个有点混乱在第一,所以我会得到你开始走上了正轨。

So I usually don't offer advice if there isn't any clear attempt/code to show for, but I remember when I was first confronted with AsyncTasks and threading in general and how it was a bit confusing at first, so I'll get you started on the right track.

因此​​,一个AsyncTask的基本上就是执行可能需要一段时间过程(如服务器负载信息,或者在你的情况下,获取文件)。它有几个方法,这些方法的详细 rel=\"nofollow\">,但我相信,对于您的情况,您只需要简单地使用 doInBackground onPostExecute 方法。你可能会做在每个那些越来越实际的图像和数据为您的ListView在 doInBackground ,然后更新的ListView来显示<$ C $的数据C> onPostExecute 。考虑例子这里概述。从本质上讲, doInBackground 方法将发送一些数据(在这种情况下,您的文件和其他的东西 - 通常是一个数组或列表,或者如果有大量的数据的东西的形式被发送)在 onPostExecute 方法,它将从那里处理数据。

So an AsyncTask basically runs a process that may take a while (such as loading information from a server or, in your case, fetching files). It has a couple methods that are detailed here, but I believe, for your scenario, you will simply need to use the doInBackground and onPostExecute methods. What you'll probably be doing in each of those is getting the actual images and data for your ListView in doInBackground and then updating the ListView to display that data in onPostExecute. Consider the examples outlined here. Essentially, the doInBackground method will send some data (in this case your files and other stuff - usually in a form of an array or List or something if there's lots of data being sent) to the onPostExecute method which will handle the data from there.

发生了什么事是,你负担过重的主UI线程,程序将等待您的UI间歇性图像的获取和加载。 的AsyncTask 抛出了所有的工作,以单独的工作线程需要照顾这个要求。负担过重的问题UI线程,当往往出现如程序意外关闭,因为Android的告示,在主应用程序线程使用太多的资源(在你的code没有实际的错误)。

What's happening is that you're overburdening your main UI thread and the program will wait for the fetching and loading of the images intermittently with your UI. AsyncTask takes care of this for you by throwing all the work to separate worker threads. Problems usually arise when overburdening the UI thread, such as your program closing unexpectedly because Android notices that the main application thread is using too many resources (no actual bugs in your code).

对于图像数据的延迟加载,我并不完全确定它是如何工作(从未使用过),但<一href=\"http://stackoverflow.com/questions/2912054/lazy-load-images-on-listview-in-androidbeginner-level\">this看来真的是有帮助的。

As for the Lazy Load of the image data, I'm not completely sure how it works (never had to use it), but this seems really helpful.

希望这给了你一些方向。

Hope that gave you some direction.

这篇关于如何使用延迟加载或异步任务列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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