caching images that are retrieved
- by Rahul Varma
Hi,
I am retrieving a list of images and text from a web service. The images are getting displayed in the list view. But the problem is, when i scroll down the list the entire images are getting loaded once again. When i scroll twice or thrice there is a OutofMemory occuring... Can anyone tell me how to cache the images and also to avoid the loading of the images that are already loaded when i scroll down. I have tried to increase inSampleSize but it didnt work... Here's the code....
public static Bitmap loadImageFromUrl(String url) {
InputStream inputStream;
Bitmap b;
try {
inputStream = (InputStream) new URL(url).getContent();
BitmapFactory.Options bpo= new BitmapFactory.Options();
b=BitmapFactory.decodeStream(inputStream, null,bpo );
b.recycle();
bpo.inSampleSize=2;
return b;
} catch (IOException e) {
throw new RuntimeException(e);
}
// return null;
}