#Region List Of Colors custom Dialog
Sub btnListOfColors_Click
If ListOfColorsPanel.IsInitialized = False Then CreateListOfColorsLayout
Wait For (Dialog.ShowCustom(ListOfColorsPanel, "", "", "CANCEL")) Complete (Result As Int)
If Result = XUI.DialogResponse_Positive Then
Base.Color = ListOfColorsPanel.Tag
End If
End Sub
Sub CreateListOfColorsLayout
ListOfColorsPanel = XUI.CreatePanel("")
ListOfColorsPanel.SetLayoutAnimated(0, 0, 0, 300dip, 300dip)
ListOfColorsPanel.LoadLayout("ListTemplate") 'ListTemplate is part of XUI Views library.
CustomListView1.sv.SetColorAndBorder(XUI.Color_Transparent, 0, 0, 0)
For Each line As String In File.ReadList(File.DirAssets, "colors.txt")
Dim s() As String = Regex.Split(":", line)
Dim Name As String = s(0)
Dim Color As Int = Bit.Or(0xff000000, Bit.ParseInt(s(1), 16))
Dim item As B4XView = XUI.CreatePanel("")
item.SetLayoutAnimated(0, 0, 0, ListOfColorsPanel.Width, 50dip)
CustomListView1.Add(item, Array(Name,Color))
Next
End Sub
'lazy creation of the items.
Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For i = Max(0, FirstIndex - 5) To Min(CustomListView1.Size - 1, LastIndex + 5)
Dim p As B4XView = CustomListView1.GetPanel(i)
If p.NumberOfViews = 0 Then
p.LoadLayout("ListOfColors")
Dim NameAndValue() As Object = CustomListView1.GetValue(i)
ColorLabel.Text = NameAndValue(0)
ColorPanel.Color = NameAndValue(1)
End If
Next
End Sub
Sub CustomListView1_ItemClick (Index As Int, Value As Object)
Dialog.Close(XUI.DialogResponse_Positive)
Dim NameAndValue() As Object = Value
ListOfColorsPanel.Tag = NameAndValue(1)
End Sub
#End Region