I have an endless Preoptimized CLV that works ok except for populating imageview1. The only way I got it to populate was to put this line:
in the: Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int) which means I am loading the bitmap file every record, not the proper way. Is there away to avoid loading the file for each image every scroll. I am having trouble with: ad.img. My relevant code in question is below:
Thank you
EDIT 040920: I changed part of my code to this and it seems to work, but not sure if is the best approach
I also commented the not needed line: ImageView1.Bitmap=.............. in Sub clv_VisibleRangeChanged (F
B4X:
ImageView1.Bitmap=LoadBitmapResize(File.DirAssets,ad.flagname,ImageView1.Width, ImageView1.Height, True)
Thank you
B4X:
Type AllData(img As Bitmap, flagname As String) 'in Globals
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main") 'has clv only
PCLV.Initialize(Me, "PCLV", clv)
l.Initialize
MyList.Initialize
l = File.ListFiles(File.DirAssets)
For i=0 To l.Size -1
Dim MyFile As String = l.Get(i)
If MyFile.EndsWith(".png") Then MyList.Add(MyFile)
Next
MyList.Sort(True)
NumberOfRealItems = MyList.Size
For i = 0 To 1000
Dim ad As AllData
ad.flagname= MyList.Get(i Mod NumberOfRealItems)
PCLV.AddItem(150dip, Rnd(0xff000000, -1),ad)
Next
PCLV.Commit
Sleep(0)
clv.JumpToItem(500 - (500 Mod NumberOfRealItems))
End Sub
Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
Dim item As CLVItem = clv.GetRawListItem(i)
Dim pnl As B4XView = xui.CreatePanel("")
' item.Panel.AddView(pnl, 0, 0, item.Panel.Width, 100dip)
item.Panel.AddView(pnl, 0, 0, item.Panel.Width-50dip, item.Panel.Height)
'Create the item layout
pnl.LoadLayout("cellitem") 'has imageview1 and Label1
Dim ad As AllData
ad=item.Value
Label1.Text = ad.flagname
Label1.TextColor = xui.Color_Yellow
Label1.SetColorAndBorder(xui.Color_Red, 5dip, xui.Color_Yellow, 10dip)
' ImageView1.Bitmap = Null
ImageView1.Bitmap=LoadBitmapResize(File.DirAssets,ad.flagname,ImageView1.Width, ImageView1.Height, True)
' ImageView1.Bitmap= ad.img
Next
End Sub
EDIT 040920: I changed part of my code to this and it seems to work, but not sure if is the best approach
B4X:
For i = 0 To 1000
Dim ad As AllData
ad.flagname= MyList.Get(i Mod NumberOfRealItems)
ad.img = LoadBitmapResize(File.DirAssets, ad.flagname, 100dip, 75dip, True)
PCLV.AddItem(150dip, Rnd(0xff000000, -1),ad) '85dip vertical
Next
Last edited: