When iterating all views the CustomListViews are shown as "BALayout". That means I can't assign it to a CustomListView object.
B4X:
Dim ClvTemp As CustomListView
For Each SingleView As View In Activity.GetAllViewsRecursive
' SingleView is a BALayout, not a CustomListView
ClvTemp = SingleView
' Now ClvTemp is not a CustomListView anymore. So I can't refer to...
Next
CLVTemp.AsView.Tag = CLVTemp
'later
For Each SingleView As B4XView In Activity.GetAllViewsRecursive
If SingleView.Tag Is CustomListView Them
Dim c As CustomListView = SingleView.Tag
End If
Next
Thank you very much for your prompt answer! My problem is that I use the Tag-Property in the designer for another purpose (Text for grouping some CustomListViews as an array, like shown in one of your posts in this forum). So, if I store a link to a CLV-Object my Text-Tag will be overwritten.
One solution is to add another property "Tag" to the Class CustomListView and use this for tagging with text. But this means modifying the CustomListView class. Another solution is to violate the sv member's tag as another Tag, because it is unused. This works. Is it a good solution or do you have a better idea?
The best solutions would be if CustomLIstView behaves the same as all other views, especially when iterating.
B4X:
Sub Globals
Private clvDataCol0 As CustomListView
Private clvDataCol1 As CustomListView
Private clvDataCol2 As CustomListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim B4xViewTemp As B4XView
clvDataCol0.sv.Tag = clvDataCol0.AsView.Tag
clvDataCol0.AsView.Tag = clvDataCol0
clvDataCol1.sv.Tag = clvDataCol1.AsView.Tag
clvDataCol1.AsView.Tag = clvDataCol1
clvDataCol2.sv.Tag = clvDataCol2.AsView.Tag
clvDataCol2.AsView.Tag = clvDataCol2
End Sub
Sub CollectListViews(RefActivity As Activity, FindArrayName As String) As CustomListView()
Dim DelimiterIndex As Int
Dim Element As Int
Dim NodeName As String
Dim ArrayName As String
Dim ListViewMap As Map
Dim ListViewList As List
Dim ClvTemp As CustomListView
ListViewMap.Initialize
ListViewList.Initialize
For Each SingleView As B4XView In RefActivity.GetAllViewsRecursive
If SingleView.Tag Is CustomListView Then
ClvTemp = SingleView.Tag
NodeName = ClvTemp.sv.Tag
DelimiterIndex = NodeName.IndexOf("_")
If DelimiterIndex <> -1 Then
ArrayName = NodeName.SubString2(0, DelimiterIndex)
Element = NodeName.SubString(DelimiterIndex + 1)
If ArrayName = FindArrayName Then
ListViewMap.Put(Element, ClvTemp)
ListViewList.Add(Element)
End If
End If
End If
Next
ListViewList.Sort(True)
Dim ListViewArr(ListViewList.Size) As CustomListView
For i = 0 To ListViewArr.Length - 1
ListViewArr(i) = ListViewMap.GetValueAt(ListViewList.Get(i))
Next
Return ListViewArr
End Sub
Yes, but if you have a lot of views you need a new and global map for every single view, because the Tag stores a reference only. That makes it very unhandy... A map in the class, or another property is much better, because with every new object you get this information automatically and you don't need parallel corresponding variables.