How can one instantly Update PCLV/CLV Item views to reflect changes from List of Files in a target Folder . Looking at the image below adapted from preoptimized CLV given as example from Erel. I want instant item to show in customlistview for example as item 7 in the image below when new images is submitted to a folder with list of images in dirinternal without recreating activity as in using: B4XPage_Created(Root). Once i click submit or refresh button, last item submitted to List of Files in a target Folder should reflect as no 7 item in the image below instantly without recreating activity as usually experienced when B4XPage_Created(Root) is used.
This is how affected part of my code look like. I just need something like update codei.e sub update that when clicked or put somewhere within the code will update CLV alone to display new item in the list without recreating activity:
This is how affected part of my code look like. I just need something like update codei.e sub update that when clicked or put somewhere within the code will update CLV alone to display new item in the list without recreating activity:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
Try
Root = Root1
'load the layout to Root
Root.LoadLayout("livescangB2")
recognizer.Initialize
chooser.Initialize(Me, "chooser")
TextEngine.Initialize(Root)
BBScrollingLabel1.TextEngine = TextEngine
'clv stats......................
If File.IsDirectory(xui.DefaultFolder, B4XPages.MainPage.ocrbasefolder & "/ultimateocr") = False Then
File.MakeDir(xui.DefaultFolder, B4XPages.MainPage.ocrbasefolder & "/ultimateocr")
End If
If File.IsDirectory(xui.DefaultFolder, B4XPages.MainPage.ocrbasefolder & "/ultimateocr" &"/workplace") = False Then
File.MakeDir(xui.DefaultFolder, B4XPages.MainPage.ocrbasefolder & "/ultimateocr" &"/workplace")
End If
CustomListView1.AnimationDuration = 0
fp.Initialize(Me,"fp",Root)
Dialog2.Initialize(Root)
Dialog2.Title = "Enter/Edit Album Info"
PCLV.Initialize(Me, "PCLV", CustomListView1)
List1.Initialize
PCLV.ShowScrollBar = False 'True 'False 'no fast scrolling
PCLV.ExtraItems = 3
Dim heightbb As Int
If xui.IsB4J Then heightbb = 200dip Else heightbb = 150dip
'list files from folderand add each of tem to list1
Wait For (File.ListFilesAsync(xui.DefaultFolder&"/" & B4XPages.MainPage.ocrbasefolder &"/ultimateocr")) Complete (Success As Boolean, Files As List)
If Success Then
For Each f As String In Files
' If filenm2b.EndsWith(".jpg") Or filenm2b.EndsWith(".png") Or filenm2b.EndsWith(".bmp") And Not(filenm2b.EndsWith(".ini")) Then
If f.EndsWith(".jpg") Or f.EndsWith(".png") Or f.EndsWith(".bmp") Or f.EndsWith(".jpeg") Or f.EndsWith(".webp") Or f.EndsWith(".gif") Or f.EndsWith(".pdf") And Not(f.EndsWith(".ini")) Then ' And Not(f.EndsWith(".ini")
List1.Add(File.Combine(xui.DefaultFolder&"/" &B4XPages.MainPage.ocrbasefolder &"/ultimateocr", f))
End If
Next
End If
For i = 0 To List1.Size-1 Step 3 'add from list 'i changed from 0
Log(i)
PCLV.AddItem(heightbb, xui.Color_White, CreateMyImageData(i))
Next
'...........................
Next
'........................
PCLV.ShowScrollBar = False 'no fast scrolling
' PCLV.ExtraItems = 3
PCLV.Commit
Catch
Log(LastException)
End Try
End Sub
Sub PCLV_HintRequested (Index As Int) As Object
' Dim word As String = CustomListView1.GetValue(Index)
Return CreateMyImageData(Index)
End Sub
Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
Try
For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
Dim item As CLVItem = CustomListView1.GetRawListItem(i)
pnl = xui.CreatePanel("")
item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height) 'item.Panel.Width, item.Panel.Height
Dim data As MyImageDatafavmix = item.Value
'Create the item layout
pnl.LoadLayout("itemocr")
Wait For (File.ListFilesAsync(xui.DefaultFolder&"/" & B4XPages.MainPage.ocrbasefolder &"/ultimateocr")) Complete (Success As Boolean, Files As List)
If Success Then
For x = 0 To 2
Dim t As Int = data.IndexOfFirstImage + x
If t >= List1.Size Then '
Exit
End If
filenm2b = (List1.Get(t)) 'i should always take note in b4xtable or album.can be used for tag to identify each cell
filenm2b = filenm2b.SubString(filenm2b.LastIndexOf("/") + 1)
Dim idx As Int = data.IndexOfFirstImage + x
pnl.GetView(x+3).GetView(0).Text = idx & "Img2Txt:" & $"$1.2{File.Size(xui.DefaultFolder, B4XPages.MainPage.ocrbasefolder &"/ultimateocr" & "/" & filenm2b) / 1024 / 1024} MB"$ 'filenm2b
If filenm2b.EndsWith(".jpg") Or filenm2b.EndsWith(".png") Or filenm2b.EndsWith(".bmp") Or filenm2b.EndsWith(".jpeg") Or filenm2b.EndsWith(".webp") And Not(filenm2b.EndsWith(".ini")) Then
pnl.GetView(x).Tag = filenm2b
Try
'
pnl.GetView(x).GetView(0).LoadLayout("b4ximagealb")
B4XImageView1.Load(xui.DefaultFolder, B4XPages.MainPage.ocrbasefolder &"/ultimateocr" & "/"&filenm2b)
B4XImageView1.ResizeMode = "FILL_NO_DISTORTIONS"
B4XImageView1.mBase.Left = 0%x
B4XImageView1.mBase.Width = 100%x ' CustomListView1.GetPanel(i).width '100%x
B4XImageView1.mBase.Top = 0%y
B4XImageView1.mBase.Height = 100%y
Catch
Log("Error loading faq.html: " & LastException.Message)
End Try
Sleep(0)
swtbutton1(filenm2b,pnl.GetView(x)) 'left
swtbutton2(filenm2b,pnl.GetView(x)) 'right
swtbutton3(filenm2b,pnl.GetView(x)) 'buttom
Next
End If
Next
AdvancedSnap.Initialize(CustomListView1)
AdvancedSnap.InstantSnap = True
Catch
Log(LastException)
End Try
End Sub
Last edited: