Adil Bhatty
Adil Bhatty

Reputation: 17340

ListView scrolling lag in android

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 disable 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

Upvotes: 1

Views: 6383

Answers (3)

Vasile Surdu
Vasile Surdu

Reputation: 1213

use this library for downloading images in background and caching.. it won't hurt the UI https://github.com/koush/UrlImageViewHelper

Upvotes: 2

Bryan Denny
Bryan Denny

Reputation: 27596

Are you lazy loading your images? See this question for details.

Upvotes: 1

Alex Volovoy
Alex Volovoy

Reputation: 68444

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

Upvotes: 3

Related Questions