Labels and scrollview memory limits

icebold

Member
Licensed User
Longtime User
Hi guys,
I wrote the following code to display DB content into labels ( L ) added in one svrollview ( SV )

B4X:
Dim sql1 As SQL
Dim in As Cursor
dim L(300) as label

sql1.Initialize(File.DirDefaultExternal,nomedb,False)
in=sql1.ExecQuery("SELECT * FROM MYTAB")

SV.ScrollPosition=0
SV.Panel.Height=in.RowCount*25DIP

For i=0 To in.RowCount-1
   in.Position=i
   L(i+1).Initialize("cella")
   L(i+1).Text=in.GetString("VALUE")
   L(i+1).Gravity=Gravity.CENTER
        SV.Panel.AddView(L(i+1),0dip,25DIP*i,300DIP, 25DIP)
Next

in.Close
sql1.Close

this example code can only display 300 labels ( limit at 300 in the code )
my question is : how many labels could I display in a scrollview reading from a DB ? if the records of my db were 3000, would be possible to display them in the Scrollview having no memory error/overflow ?

Thanks for your support
 

icebold

Member
Licensed User
Longtime User
I tried on my device ( samsung S2 ) and works fine but I don't know if it would work on other devices with less memory. :confused:
 
Upvote 0

derez

Expert
Licensed User
Longtime User
The quantity of labels depends on the specific device memory and the current running programs.
If you don't need the labels for further actions, but need only to display their content, you can show them not as an array but as a single label which is re-initialized every cycle of the loop. I believe this saves memory.
I used this trick to save memory with imageviews on a scrollview, and have all the pictures visible with only one imageview re-initialized.
The result is that you can see all the labels but their properties are those of the last.
 
Last edited:
Upvote 0

timwil

Active Member
Licensed User
Longtime User
If you want to post a copy of your app I would be willing to run it in my Samsung Galaxy Mini and I also have access to a Coby Kyros, Viewsonic VPAD7 and a ZT180 and report the results
 
Upvote 0

Woinowski

Active Member
Licensed User
Longtime User
I wouls suggest ListView

Have you thought about using a ListView instead of a handmade solution? Advantages I would expect

  • More efficient use of memory (no warranty :D)
  • No need for hard coded number of entries
  • Slightly better performance
  • Option for two-lined entries with different layouts
  • More "Android look'n'feel"
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
I wrote an app that use listview to show 20000 (yes 20k) items and it worked fine. A little problem is you need to wait about 10 seconds :D
 
Upvote 0

icebold

Member
Licensed User
Longtime User
Thanks again for your precious support guys!

I choosed to follow another solution in order to the new project design that has changed.
The code is almost the same of my first post but now I show 3 labels for each lines instead of one: tapping on labels I can edit their properties so I need to load them in an array.

To prevent memory overflow and low speed performance I choosed to load only 100 lines each time I press a button to "show other 100 records" ( in this way I load only 300 labels, not much slow on devices I tested on ).

When I finish this project I will post this routine hoping it would help someone :)
( I still have much work to do :( )

Thanks again :)
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
It would be really nice to have something like I use in Windows where it is a virtual listview. You tell it how many items you have so it can draw the scrollbars correctly then as a particular item scrolls into view (possibly even a buffer of 10 or so) it requests the text for that item so you can populate it on the fly from a database and not consume memory holding everything in RAM.
 
Upvote 0
Top