Android Question Out Of Memory on ListView

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
The ListView Control with a large number of itens WITH bitmaps from photos, got OUT OF MEMORY error.

What´s the best (or correct) way to show a image list from a folder (I got this error after some photos loaded)



B4X:
lstFiles.AddTwoLinesAndBitmap2( "text1","text2", LoadBitmapSample(imageDir,imageFile,512,512),strFilePath)

Error in this line after some photos:

Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
Downsampling image due to lack of memory: 16
Downsampling image due to lack of memory: 32
Downsampling image due to lack of memory: 64
java.lang.RuntimeException: Error loading bitmap (OutOfMemoryError)
 

eurojam

Well-Known Member
Licensed User
Longtime User
you can use a scrollview instead and only load the images which are visible in the scrollview (using the ScrollChanged Event) instead of loading all bitmaps at the start of your initialize routine
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The issue is not related to the ListView. Large images require a lot of memory. You should either use smaller dimensions (note that you are missing the dip units) or a more sophisticated solution where only the visible images are loaded.

https://www.b4x.com/android/forum/posts/210230/

Check UlitmateListView. I'm pretty sure that it implements such a solution.
 
Upvote 0
Top