For various Android applications, I need large ListView
s, i.e. such views with 100-300 entries.
All entries must be loaded in bulk when the application
1) To solve your memory problem with HashMap
: Can you use WeakHashMap
so that images are recycled when needed? The same should work for the ArrayList
you mentioned in the beginning, if your CustomType
has weak references to images.
2) What about NOT loading images while user scrolls through the list, but instead when user stops scrolling, load images at that moment. Yes, the list will not look fancy without images, but it will be very efficient during scroll, and while user scrolls he does not see details anyway. Techinally it should work like this:
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
// Don't care.
}
@Override
public void onScrollStateChanged(final AbsListView view, int scrollState) {
// Load images here. ListView can tell you what rows are visible, you load images for these rows and update corresponding View-s.
}
})
3) I have an app that loads about 300 images during app start and keeps them for app lifetime. So that's an issue for me too, but so far I have seen very few OOM reports and I suspect they happened because of a different leak. I try to save some memory by using RGB_565
profile for ListView images (there's no significant difference in quality for this purpose) and I use 96x96 max image size, that should be enough for standard list item height.