If Starter.SirLockalot <> Null then
TOCCLV = Starter.SirLockalot 'reuse previous ("saved") instance
'might need to update view's parent to be the newly-created Activity rather than the old (deleted) Activity
Else
TOCCLV.Initialize 'or has LoadLayout already done this for you?
'build up TOCCLV
Starter.SirLockalot = TOCCLV 'could probably do this earlier, but... feels safer to wait until TOCCLV resembles something valid
End If
I gave it a red-hot go as well, likewise no success. Also tried stuff like keeping a separate list of the panels, and adding them to a CLV if the CLV has fewer elements than the list. Well, it was worth a shot.Well try it in many differents ways
I too am interested to know if there is a way of doing it.So i'm open to suggestions.
Your app users are going to be spending a lot of time scrolling through that list. Can you organize the TOC into two or three levels, which would reduce the sizes down to more manageable 30-to-100 items each?i'm working on another TOC that will contains 6500 to 7000 items to load
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private EditText1 As EditText
Dim CustomListView1 As CustomListView
Dim L As List
Dim A() As String 'duplicate of L for quicker searching: already ToUpperCase'd, and no need to cast to string
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
CreateSampleList(2000)
UpdateArrayFromList
LoadFirst100
End Sub
Sub CreateSampleList(N As Int)
L.Initialize
Dim StartTime As Long = DateTime.now
For I = 1 To N
Dim S As String = Chr(Rnd(65, 65+26)) & Chr(Rnd(65, 65+26)) & Chr(Rnd(65, 65+26)) & " " & I
L.Add(S)
Next
Dim EndTime As Long = DateTime.Now
Log(EndTime - StartTime)
End Sub
Sub UpdateArrayFromList
Dim A(L.Size) As String
Dim S As String
For I = 0 To L.Size - 1
S = L.Get(I)
A(I) = S.ToUpperCase
Next
End Sub
Sub LoadFirst100
Dim SearchString As String = EditText1.Text.ToUpperCase
CustomListView1.Clear
Dim LineNumber As Int = 0
CustomListView1.DefaultTextColor = Colors.Black
For I = 0 To L.Size - 1
If A(I).Contains(SearchString) Then
LineNumber = LineNumber + 1
CustomListView1.AddTextItem(L.Get(I), LineNumber)
Sleep(1) 'progressive update display
If LineNumber >= 100 Then
CustomListView1.AddTextItem("(more matches: refine search)", 999999)
Exit
End If
End If
Next
If LineNumber = 0 Then
CustomListView1.AddTextItem("(no matches found)", 999999)
End If
End Sub
Sub EditText1_TextChanged (Old As String, New As String)
LoadFirst100
End Sub
Or just this.4. The main problem is that it takes too long to create the lists. This means that you need to switch to lazy loading. It is quite simple to do and everything will happen very quickly.
' *******************************************************************
' load the Toc Table if not loaded
' this is where i call the loading of TOC table into the Drawer leftPanel
' *******************************************************************
Private Sub loadTocDrawerMenu(menuName As String, menuEvent As String)
Dim isOpen As Boolean = False
Dim menu As String = menuEvent
'Log("Menu:" & menuEvent)
Try
If Drawer.LeftOpen = True Then ' the other mmenu is active close the screen
Drawer.LeftOpen = False
menu = Drawer.LeftPanel.tag
'Log("Menu tag:" & Drawer.LeftPanel.Tag)
isOpen = True
Else
menu = Drawer.LeftPanel.tag
isOpen = False
End If
Catch
Log("Drawer leftOpen: not Defined")
End Try
'Log("Drawer leftOpen:" & Drawer.leftOpen)
If isOpen = False And menu <> menuEvent Then
ProgressDialogShow("Chargement de la table des matières un instant..")
Sleep(30)
Drawer.LeftPanel.Color = Colors.white
Drawer.LeftPanel.RemoveAllViews
Drawer.LeftPanel.Top = 70Dip
Drawer.LeftPanel.Width = deviceScreen.ScreenX - 1
Drawer.LeftPanel.Height = deviceScreen.ScreenY - 125
Drawer.LeftPanel.LoadLayout(menuName)
Drawer.LeftPanel.Tag = menuEvent
loadTocTable ' load the TOC table Sub
Drawer.LeftOpen = True
TableView1.Base_Resize(Drawer.LeftPanel.Width,Drawer.LeftPanel.Height - 40)
ProgressDialogHide
Else
Drawer.LeftOpen = True
End If
End Sub
' Type Toc(Parent As String,nodeType As String,children As String,color As Long,Texte As String,Link As String,Title As String)
private Sub loadTocTable()
' set alpha indexes from content of toc table
' display the custom list views cards for toc content
Dim c,d As ColorDrawable
c.initialize2(Colors.White,0,0,Colors.Gray)
d.Initialize2(Colors.White,0,0,Colors.Transparent)
tocLabel.Gravity = Bit.Or(Gravity.CENTER, Gravity.TOP)
tocLabel.TextSize = 28
tocLabel.Text = "TABLE DES MATIERES"
tocLabel.TextColor = Colors.black
Drawer.LeftPanel.Tag = "toc"
' this load all the items from the list from Beginning to End
For i = 0 To eServiceModule.tocList.Size-1
Dim oPos As Toc ' Defined user type
oPos.Initialize
oPos = eServiceModule.tocList.Get(i)
Dim pnl As B4XView = Xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, TableView1.AsView.Width, 61dip)
pnl.LoadLayout("node")
pnl.Color = Colors.white
Textview1.Background = c
Textview1.Color = Colors.white
If oPos.nodeType="F" Then
Textview1.Width = pnl.width
TableView1.Add(pnl, oPos.link)
Textview1.TextSize = 22
Textview1.Tag = i
Textview1.textColor = convertGreenColor(oPos.color)
Textview1.Text = oPos.Texte
Textview1.Gravity = Bit.Or(Gravity.CENTER, Gravity.TOP)
Else if oPos.nodeType = "D" Then
Textview1.Width = pnl.width
TableView1.Add(pnl, oPos.link)
Textview1.Tag = i
Textview1.TextSize = 22
Textview1.Padding = Array As Int(15dip,0,0,0)
Textview1.TextColor = convertGreenColor(oPos.Color)
Textview1.Text = Chr(0xF03C) & " " & oPos.Texte
Textview1.Gravity = Bit.Or(Gravity.LEFT, Gravity.TOP)
End If
Next
End Sub
Sleep(0) is the new DoEvents (but note the immediate-fork-return aspect of it)but we don't have the DoEvents anymore
I should check: I've been assuming that TOC is table of contents, as in the unsorted index at the front of a book. Is this correct?I'm Working on an idea
That'd be great, I'm interested to see how this pans outI'll keep you posted...
You could kludge a ReachEnd event by comparing the VisibleRangeChanged event's FirstIndex to 0 and LastIndex to CLV.Size.if my idea works, that will solve a lot of problems
Sub TableView1_ReachEnd
Log("Reach end of list")
calculateTocPositionAndDisplay
End Sub
' This is where to calculate the part of the list that will be loaded when we reach the end of list (customListview)
Private Sub calculateTocPositionAndDisplay()
Dim Start, Ending, Steps, Count As Int ' those pointers are stored in service module
Start = eServiceModule.BeginingListPointer ' Pointer for beginning of index to be displayed from list
Ending = eServiceModule.EndingListPointer ' Pointer for ending of index to be displayed from list
Steps = eServiceModule.itemsToLoad ' Number of items to reload each time we scroll down
Count = eServiceModule.tocList.Size-1 ' total items in the main list not ListView
' i keept these conditions in case i decided to do something else here
If scrollDirection = SCROLL_DIRECTION_DOWN Then
' Log("SCrolling Down")
Start = Start + Steps + 1
If Start > Count Then
Start = Count
eServiceModule.BeginingListPointer = Start
End If
eServiceModule.BeginingListPointer = Start
Ending = Start + Steps
If Ending > Count Then
Ending = Count
If eServiceModule.EndingListPointer < Count Then
loadTocListPart(Start,Ending)
End If
eServiceModule.EndingListPointer = Ending
Else
loadTocListPart(Start, Ending)
End If
Else if scrollDirection = SCROLL_DIRECTION_UP Then
' we could do something here
End If
End Sub
Sub TableView1_ScrollChanged (Offset As Int)
Dim dipOffset As Int = 10 ' slight offset to test upon so a difference of 1 will not trigger
If lastScrollOffset <= Offset Or (lastScrollOffset <= dipOffset And Offset <= dipOffset) Then
scrollDirection = SCROLL_DIRECTION_DOWN
' we are scrolling Down into the list
Else
scrollDirection = SCROLL_DIRECTION_UP
End If
' we are scrolling Up into the list
' the var lastScrollOffset is stored in the Process_Globals
lastScrollOffset = Offset
End Sub
Private Sub loadTocListPart(Begin As Int, Ending As Int)
Dim c As ColorDrawable
c.initialize2(Colors.White,0,0,Colors.Gray)
tocLabel.Gravity = Bit.Or(Gravity.CENTER, Gravity.TOP)
tocLabel.TextSize = 28
tocLabel.Text = "TABLE DES MATIERES"
tocLabel.TextColor = Colors.black
For i = Begin To Ending
Dim oPos As Toc
oPos.Initialize
oPos = eServiceModule.tocList.Get(i)
Dim pnl As B4XView = Xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, TableView1.AsView.Width, 61dip)
pnl.LoadLayout("node")
pnl.Color = Colors.white
Textview1.Background = c
Textview1.Color = Colors.white
If oPos.nodeType="F" Then
Textview1.Width = pnl.width
TableView1.Add(pnl, oPos.link)
Textview1.TextSize = 22
Textview1.Tag = i
Textview1.textColor = convertGreenColor(oPos.color)
Textview1.Text = oPos.Texte
Textview1.Gravity = Bit.Or(Gravity.LEFT, Gravity.TOP) ' change to gravity.CENTER after debuging
Else if oPos.nodeType = "D" Then
Textview1.Width = pnl.width
TableView1.Add(pnl, oPos.link)
Textview1.Tag = i
Textview1.TextSize = 22
Textview1.Padding = Array As Int(15dip,0,0,0)
Textview1.TextColor = convertGreenColor(oPos.Color)
Textview1.Text = Chr(0xF03C) & " " & oPos.Texte
Textview1.Gravity = Bit.Or(Gravity.LEFT, Gravity.TOP)
End If
Next
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?