I agree with Raghav Sood. I have added a bit more of how to display images in listview or gridview.
I have used Universal Image loader to display large number of images in listview.
You should recycle bitmaps when not in use.
http://www.youtube.com/watch?v=_CruQY55HOk. Talk is about memoy management and memory leaks and how to avoid it. If you ever run into memory leaks you can use a MAT Analyzer to find memory leaks. The video also talks about using MAT Analyzer and demonstrates how to get rid of memory leaks.
When you display images in listview you need to recycle the views. Views that are visible are not recycled.
To display images in gridview or listview you can use univarsal image loader. A improved version of lazy loading. Images are cached. You can display images localy or from a server.
https://github.com/nostra13/Android-Universal-Image-Loader
File cacheDir = StorageUtils.getOwnCacheDirectory(context, "your folder");
// Get singletone instance of ImageLoader
imageLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//display stub image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
In your getView()
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options
You can configure with other options to suit your needs.
Along with Universal Image Loader you can view holder for smooth scrolling and performance. http://developer.android.com/training/improving-layouts/smooth-scrolling.html.
http://www.youtube.com/watch?v=wDBM6wVEO70. The talk is about viewholder and performance.