Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:06:14+00:00 2026-06-03T03:06:14+00:00

I have a custom ListView that does a lazy load of remote images. When

  • 0

I have a custom ListView that does a lazy load of remote images. When you click a listitem, it starts a new Activity and displays the image in a webview.
The problem is, the webview always loads the images, even if the image was preloaded by the listview adapter. I want the WebView to load the image only if it was not preloaded!

Here is how I preload the images in the listview:

public void DisplayImage(String url, ImageView imageView)
{
    imageViews.put(imageView, url);
    Bitmap bitmap=memoryCache.get(url);
    if(bitmap!=null)
        imageView.setImageBitmap(bitmap);
    else
    {
        queuePhoto(url, imageView);
        imageView.setImageResource(stub_id);
    }
}

The lazy-loaded images are stored in a FileCache:

public FileCache(Context context){
    //Find the dir to save cached images
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
    else
        cacheDir=context.getCacheDir();
    if(!cacheDir.exists())
        cacheDir.mkdirs();
}

public File getFile(String url){
    //I identify images by hashcode. Not a perfect solution, good for the demo.
    String filename=String.valueOf(url.hashCode());
    //Another possible solution (thanks to grantland)
    //String filename = URLEncoder.encode(url);
    File f = new File(cacheDir, filename);
    return f;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:06:15+00:00Added an answer on June 3, 2026 at 3:06 am

    The proper way to deal with this is to install an HttpResponseCache with the client/connection you use for downloading the images. Although a platform implementation wasn’t provided until API level 13, there’s a backported version that works for Android 1.5 and up. This caching mechanism is only suitable for Http(s)URLConnection though; if you use HttpClient you will want Apache’s HttpClient Caching Module.

    If you’re after a quick solution, you can potentially also have a look at WebViewClient‘s shouldInterceptRequest(...) method. By overriding that method, you can intercept requests that get fired whenever a resource is about to be fetched, including images, if I’m not mistaken. You could implement a check that does a local lookup to see if the image has already been downloaded and if so, return it wrapped in a WebResourceResponse. If the file isn’t locally available, simply don’t do anything and let the client handle the downloading. The downside to this is that anything downloaded by the webclient will not be available to the lazy image loader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom baseadapter which does some lazy loading of some images, and
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have a Custom ListView that contains a vertical LinearLayout of horizontal LinearLayouts for
I have a custom control that is derived from ListView . This list view
I have a ListView that is being populated with a custom adapter. I'd like
I have a custom control template for a ListView that puts an extra line
I have a custom listview row that contains a number of textView components. Instead
I have a custom list view that is getting data from server and changing
I have a custom listView with editText in each row to carry value entered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.