ListView capacity/limit

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I use ListView TwoLinesAndBitmap.
My application crashes during load of listview.

Using a small database of 3 records, all works fine.

Loading a database of about 2000 records and so 2000 images it crashed.

Just using listview without images it works fine.

Is there a limit of bitmaps loaded in listview or is there a limit of bitmap size used with listview?

Part of Source:
Sub FetchTitelLijst
Dim i As Int
Dim Cursor1 As Cursor
Dim txt, str1 As String

ListView1.Clear
txt = "SELECT Titel, Image, Aanschaf, Soort, Status, ROWID FROM " & DBTableName & " WHERE Titel LIKE '%" & Zoeksleutel.Text & "%' OR EAN LIKE '%" & Zoeksleutel.Text & "%' ORDER BY SorteerTitel"

Cursor1 = SQL1.ExecQuery(txt)

For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
Dim sil As SixLines
sil.First = Cursor1.GetString("Titel")
str1 = Cursor1.GetString("Aanschaf")
sil.Third = Cursor1.GetString("Soort")
sil.Four = Cursor1.GetString("Image")
sil.Fith = Cursor1.GetString("Status")
sil.Six = Cursor1.GetString("ROWID")

sil.Second = sil.Third & " / " & sil.Fith & " / " & str1.SubString2(8,10) & "-" & str1.SubString2(5,7) & "-" & str1.SubString2(0,4)

If File.Exists(ImagePath, sil.Four & "f.jpg") = True Then
ListView1.AddTwoLinesAndBitmap2(sil.First, sil.Second, LoadBitmap(ImagePath, sil.Four & "f.jpg"), sil)
Else
ListView1.AddTwoLines2(sil.First, sil.Second, sil)
End If
Next
Cursor1.Close
ListView1.RequestFocus
End Sub


Thanks,
André
 

AHilberink

Active Member
Licensed User
Longtime User
The bitmaps are copied from my PC and are used on my PC programm. This programm does the compression. I am not able to change anything of this.

May be I can catogorize, but this means no long list and always choose a letter of the alfabeth.

Is there a way to swap to SD? I do have 16Gb.

How many internal memory can I use?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
No point swapping to sd.
This is your RAM not the sdcard storage. Usually phones come with 512MB or 1GB of RAM. When your program runs it loads all your images into RAM for displaying and these are stored uncompressed. So there is not much help with compression during runtime.
If you cannot change the images, then you will have to limit the number of images being loaded, because this could cause crashes on a lot of phones.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
When will the images be loaded?

I disabled the images within the ListView. Only when klik on the row of ListView I open an ImageView.

Even then the application crashed on start. Lesser images of disable the mages works fine.

Part of source:
Sub ListView1_ItemClick(Position As Int, Value As Object)
Dim sil As SixLines : sil = Value

If File.Exists(ImagePath, sil.Four & "f.jpg") = True Then
ImageFront.Bitmap = LoadBitmap(ImageBigPath, sil.Four & "f.jpg")
ImageFront.Visible = True
Else
Msgbox("Image niet gevonden","")
End If
End Sub



Thanks,
André
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
When will the images be loaded?
On this line:
ListView1.AddTwoLinesAndBitmap2(sil.First, sil.Second, LoadBitmap(ImagePath, sil.Four & "f.jpg"), sil)

I disabled the images within the ListView. Only when klik on the row of ListView I open an ImageView.

Even then the application crashed on start. Lesser images of disable the mages works fine.

Part of source:
Sub ListView1_ItemClick(Position As Int, Value As Object)
Dim sil As SixLines : sil = Value

If File.Exists(ImagePath, sil.Four & "f.jpg") = True Then
ImageFront.Bitmap = LoadBitmap(ImageBigPath, sil.Four & "f.jpg")
ImageFront.Visible = True
Else
Msgbox("Image niet gevonden","")
End If
End Sub



Thanks,
André

Are you saying the application crashes at the start, even if you do not load the bitmaps?
How does it crash? What is the error message? Can you post the Logs?
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
The crash is at the start. I disabled the AddTwoLinesAndBitmap2 and set it back to AddTwoLines2. Now the images are not loading in ListView.

But after that it still crashes. It looks like the:
ImageFront.Bitmap = LoadBitmap(ImageBigPath, sil.Four & "f.jpg")
also loads the images at the start.

Removing the ImageBigPath-location and everything works fine.

The error is common: Application has stopped. Try again. (Translation from Dutch)

I don't know where to find a log-file.

Thanks for helping.

André
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Interesting. How is the ListView1_Click being executed at start up?

Do a search for Logs on the forum.
In the IDE, on your right hand, there are 4 tabs. One of them is Logs.
Press Connect on the Logs to see the logs and past them here.
If you do not see an error in the Logs then uncheck the 'filter' checkbox to view unfiltered logs.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
There is no execute of ListView1_Click at startup.
Just fill the ListView and display it.

I am not able to do tests on AVD with my xml file, only on my real phone. I don't know how to put the XML file and the Images on the virtual SD card.

This way I don't have logs.

Do you have a suggestion to create more info about the problem?

Thanks,
André
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Well we need logs to find out what the problem is.

You have 2 options:
If you want to debug on a real device, you can use the B4A bridge: http://www.b4x.com/forum/basic4andr...ge-new-way-connect-your-device.html#post45042
It will connect the B4A IDE to your phone on WiFi.

Second option is to get the xml file on the emulator.
There are several options, you can use adb (Android Debug Bridge | Android Developers)
Just use the command line tool to do (with the emulator running):
adb -e push <localfile> <remotefile>
like
adb -e push foo.txt /sdcard/foo.txt

adb is somewhere in the android sdk platform folder.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Couldn't you post your project as a zip file, or at least a reduced project that shows the problem, so we could test it with the same conditions as you. Otherwise it's almost impossible to give you a concrete answer.

Best regards.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi Klaus and thedesolatesou,

I found an error within my script. Because of the memory problem, I copied a part to the ListView1_Click function. Forgot to change ImagePath to ImageBigPath:BangHead:.

Now it is working correctly, but still the memory problem on loading the ListView exist. I tested it with much smaller images, but still.

I tested it with only letter A part and it worked, but I think I cannot use Bitmaps within the ListView. Some phones with less memory will not work. Even with the smaller images.

I don't have a solution right now, any suggestion will be appreciated.

Thanks for your kindly help.
André
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I would suggest you think about what you want to do with it. What is your application for?

Lets say you want to make a phonebook or gallery application with loads of thumbnails. You have to manage your memory efficiently and make sure your app does not crash.
Firstly, only create bitmaps the size you need to display. Dont load bigger bitmaps if you will only display them scaled down. Use createScaledBitmap for that.
Secondly, allocate a buffer in memory (mentally) of how much space you have. In 10 MB you will be able to load 160 128x128 32-bit bitmaps or 40 256x256 32-bit bitmaps. Use that as a sliding buffer to load bitmaps into the listview when you need to, no need to fill the whole listview.

I am not sure how much memory Android allocates for a process. Find that out.
These are a few things you should think about when working with bitmaps.

Interesting Article: http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/
 
Last edited:
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi thedesolatesou,

Thanks for your suggestions.

I decide to do no images within the ListView, only visible on Click.

The memory limit is mostly 16Mb as far as I found out, but I am affraid there could be users that will experience memory problems.

So this is the safest way for me.

Thanks for all your kindly help.

André
 
Upvote 0
Top