In the API demo , there is an example of an effecient list adapter in which all the bitmap are preloaded in the adapter constructor :
// Icons bound to the rows.
mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_1);
mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_2);
In case the adapter have to deals with a lot of bitmap, is it still a good practice or will it be better to do something like that in the getView :
holder.myImage.setImageDrawable(context.getResources().getDrawable(R.drawable.icon48x48_1));
Note in my case , i can have something like 10-15 possible bitmap , but only a few will be used at same time. I’m concerned by the memory used by the adapter.
Thanks
If the icons are truly 48×48 pixels, they won’t be that big, and since you have a known small set of them, preloading them is probably fine. I would not use that approach if:
You can always dump your heap from DDMS and inspect it with the Eclipse MAT plug-in to get a perspective on how much heap space is actually being used. Test it on Honeycomb or Ice Cream Sandwich, though, as you get better results for tracking bitmap heap consumption.