Android Question Loading CustomListView too slow

tsteward

Well-Known Member
Licensed User
Longtime User
I am loading a cutsomlistview as per the code below. If I don't include images its quiet fast, but as soon as I add vehicle manufacturer logos it really slows down.

Is there a better way to display a list of vehicle manufacturers and there logos?
I have included a sample logo. They are all aroung 6kb or less in size.
List is about 75 rows longs.

B4X:
ub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("VehiclesLayout")
   
    vehiclesLV.SingleLineLayout.Label.TextSize = 18
    vehiclesLV.Color = Colors.White
    vehiclesLV.SingleLineLayout.Label.TextColor = Colors.Black
    vehiclesLV.SingleLineLayout.Label.Gravity = Gravity.CENTER_HORIZONTAL
    vehiclesCLV.Initialize(Me, "vehiclesCLV")
    vehiclesPanel.AddView(vehiclesCLV.AsView, 0, 0, LVJump.Left, LVJump.Height)
    vehiclesCLV.DefaultTextBackgroundColor = Colors.DarkGray
   
    Main.CursMake = Main.sql1.ExecQuery("SELECT * FROM VehicleMakes WHERE EXISTS (Select 1 FROM Vehicles WHERE Vehicles.MakeID = VehicleMakes.MakeID) ORDER BY MakeName")
    If Main.CursMake.RowCount > 0 Then
        Dim tempMake As String
       
        For i = 0 To Main.CursMake.RowCount -1
            Main.CursMake.Position = i
            tempMake = Main.CursMake.GetString("MakeName")
            vehiclesCLV.Add(createListItem(tempMake), 62dip, "Item #t" )
        Next
    End If
End Sub

Sub createListItem (Make As String) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.RGB(151,179,207)
    Dim iv1 As ImageView
    If File.Exists(File.DirAssets, Make & ".png") Then       
       
        iv1.Initialize("iv1")
        iv1.Bitmap = LoadBitmap(File.DirAssets, Make & ".png")
    End If
    Dim b1 As Button
    b1.Initialize("Mbutton") 'all buttons click events will be handled with Sub Button_Click
    b1.Text = Make

    If iv1.IsInitialized Then
        p.AddView(iv1, 5dip, 0dip, 60dip, 60dip)
    End If
    p.AddView(b1, 75dip, 0dip, (vehiclesPanel.Width - LVJump.Width)- 80dip, 60dip) 'view #0

    'If File.Exists(File.DirAssets, Make & ".png") Then       
    'End If
    Return p
End Sub
 

Attachments

  • Screenshot_2015-09-09-18-57-06.png
    Screenshot_2015-09-09-18-57-06.png
    380.6 KB · Views: 266
  • buick.png
    buick.png
    6.3 KB · Views: 249

RandomCoder

Well-Known Member
Licensed User
Longtime User
It's not possible to show all 75 at one time so it would be a lot faster to load just the first 10 or how ever many are needed to fill the screen and then load more as required. It becomes a little complicated in the code but will be much faster. On one of my Apps I had to implement bump scrolling because they're could be hundreds or even thousands of rows required and it was out of my control how many would be shown.
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Ok so I have no got my app loading enough rows to fill the screen and a few more. The rest load as you scroll down.
This has speed it up quite a lot.

Is there a way I can do the initial load and display it then load the remaing rows whithout any user interaction?
The reason I want to do this is I previously had a seconf list next to my CLV with the alphabet. Then selecting a letter would scroll the CLV to that letter, which was a nice feature.
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
If you want high speed, use ultimate listview. It has all optimizaitons, you currently need.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top