I am having a customized list view in my application, which is showing an image and text. The Image I am getting from URL, using the code below:
private static Drawable ImageOperations(Context ctx, String url,
String saveFilename) {
try {
InputStream is = (InputStream) fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static Object fetch(String address) throws MalformedURLException,
IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
all is working perfect, except the list view scrolling, its very slow. If I di开发者_运维知识库sable the images, the scroll speed smooth-ens , but with the image enabled, it lags alot.
Is there any possible way I can reduce or remove this lagging?
Thanks
You need to do your fetching in the background. One of the examples you can use : http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
use this library for downloading images in background and caching.. it won't hurt the UI https://github.com/koush/UrlImageViewHelper
Are you lazy loading your images? See this question for details.
精彩评论