I've searched the forum and it would appear that I need to use either a Tableview or Informatix's UltimateListView to get improved performance. I'd just like to check with those more knowledgeable than I which would be the easiest way to proceed, i.e. require the least modifications to my existing code?
My app uses a Map to store information received from browse requests to a media server. The key is the ID of the object returned by the server and the value is a custom Type detailing the name of the object, and other information.
What I have at present is a Scrollview loaded with Panels, each Panel has an Imageview to the left side and a label to the right. This works fine when only a few items are contained in the Map, but slows significantly when 100's of items are present. I've attempted to use a DoEvents after every 20 panels (see refreshCount variable), but this had NO effect at all.
All advice greatly appreciated.
Thanks,
RandomCoder
My app uses a Map to store information received from browse requests to a media server. The key is the ID of the object returned by the server and the value is a custom Type detailing the name of the object, and other information.
What I have at present is a Scrollview loaded with Panels, each Panel has an Imageview to the left side and a label to the right. This works fine when only a few items are contained in the Map, but slows significantly when 100's of items are present. I've attempted to use a DoEvents after every 20 panels (see refreshCount variable), but this had NO effect at all.
B4X:
Private Sub ShowDeviceItems(itemStartPosition As Int)
Dim psv As Panel
Dim i , listBottom, fontSize, fontHeader, fontItem, refreshCount As Int
psv = svDiscoveredList.Panel
fontHeader = 35
fontItem = 20
refreshCount = 0
' Show all items from browsed results
If UPNP.browseResults.Size > 0 Then
' Remove all previous items if starting a new list
If itemStartPosition = 0 Then
psv.RemoveAllViews
scrollingLabels.Initialize
listBottom = 0
Else
listBottom = psv.Height
End If
' Add each item to scroll view
For i = itemStartPosition To UPNP.browseResults.Size - 1
Dim container As itemContainer
container.Initialize
Dim pContainer As Panel
Dim ivIcon As ImageView
Dim lItem As Label
Dim id, name, itemClass As String
container = UPNP.browseResults.GetValueAt(i)
id = UPNP.browseResults.GetKeyAt(i)
name = container.title
itemClass = container.itemClass
fontSize = fontHeader
pContainer.Initialize("ViewItem")
pContainer.Tag = id
psv.AddView(pContainer, 0, listBottom, psv.Width, 80dip)
pContainer.Color = Colors.DarkGray
' Show item icon
ivIcon.Initialize("ViewDevice")
ivIcon.Tag = id
pContainer.AddView(ivIcon, 10dip, 10dip, 60dip, 60dip)
If itemClass.Contains("object.container") Then
If name.ToLowerCase.Contains("movie") OR name.ToLowerCase.Contains("video") Then
ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "movies folder.png", 60, 60)
Else If name.ToLowerCase.Contains("music") Then
ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "music folder.png", 60, 60)
Else If name.ToLowerCase.Contains("picture") OR name.ToLowerCase.Contains("photo") Then
ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "pictures folder.png", 60, 60)
Else
ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "folder.png", 60, 60)
End If
Else If itemClass.Contains("object.item") Then
fontSize = fontItem
If itemClass.Contains("video") Then
'ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "movies file.png", 60, 60)
ivIcon.Bitmap = LoadBitmap(File.DirAssets, "movies file.png")
Else If itemClass.Contains("image") Then
ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "pictures file.png", 60, 60)
Else If itemClass.Contains("audio") Then
ivIcon.Bitmap = LoadBitmapSample(File.DirAssets, "music file.png", 60, 60)
End If
End If
' Show item name
lItem.Initialize("ViewItem")
lItem.Tag = id
pContainer.AddView(lItem, 100dip, 1dip, Activity.Width-101dip, 79dip)
lItem.TextSize = fontSize
lItem.Color = Colors.DarkGray
lItem.Typeface = Typeface.DEFAULT_BOLD
lItem.Gravity = Gravity.CENTER_VERTICAL
If name <> Null Then
lItem.Text = name
'scrollingLabels.Add(Scrolling_Labels.StartScrolling(lItem, name, True))
End If
listBottom = pContainer.Top + 85dip
Next
svDiscoveredList.Panel.Height = listBottom
refreshCount = refreshCount + 1
If refreshCount = 20 Then
refreshCount = 0
DoEvents
End If
End If
End Sub
Thanks,
RandomCoder