views:

82

answers:

2

Hi,

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

+1  A: 

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

Alex Volovoy
+1  A: 

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

Bryan Denny