B4X UI Views are really nice and easy to use multiplatform views. As a recent B4X convert, I am quite impressed.
Here’s an issue that has been giving me a headache though. In the XUI Views Example demo, when you click on the List of Colours button, a dialog pops up and shows a list of colours that you can choose one from. Clicking on one of them will set the colour of the current activity . It’s great (see original demo code at bottom of this post).
But, I have been trying to modify that specific demo so that the dialog displays at the top its window the current activity colour by scrolling to, actually jumping to the index of that colour in the scrollview.
So I added it to btnListOfColors_Click, which now looks like this.
But it will only work from the second time around, never the first time (if you're wondering, the gColourIndex is set correctly in some other part of the code).
Any idea on how to fix this without altering the library itself?
Thank you for any help.
PS: I do have a solution that works, but it involves an ugly hack between btnListOfColors_Click and CustomListView1_VisibleRangeChanged. There must be something simpler.
Original code dealing with List Of Colors custom Dialog:
Here’s an issue that has been giving me a headache though. In the XUI Views Example demo, when you click on the List of Colours button, a dialog pops up and shows a list of colours that you can choose one from. Clicking on one of them will set the colour of the current activity . It’s great (see original demo code at bottom of this post).
But, I have been trying to modify that specific demo so that the dialog displays at the top its window the current activity colour by scrolling to, actually jumping to the index of that colour in the scrollview.
B4X:
'gColourIndex: index of colour to jump to and display at top of dialog window.
CustomListView1.JumpToItem(gColourIndex)
So I added it to btnListOfColors_Click, which now looks like this.
B4X:
#Region List Of Colors custom Dialog
Sub btnListOfColors_Click
If ListOfColorsPanel.IsInitialized = False Then CreateListOfColorsLayout
'Displays the current colour at top of window
CustomListView1.JumpToItem(gColourIndex)
Wait For (Dialog.ShowCustom(ListOfColorsPanel, "", "", "CANCEL")) Complete (Result As Int)
If Result = XUI.DialogResponse_Positive Then
Base.Color = ListOfColorsPanel.Tag
End If
End Sub
But it will only work from the second time around, never the first time (if you're wondering, the gColourIndex is set correctly in some other part of the code).
Any idea on how to fix this without altering the library itself?
Thank you for any help.
PS: I do have a solution that works, but it involves an ugly hack between btnListOfColors_Click and CustomListView1_VisibleRangeChanged. There must be something simpler.
Original code dealing with List Of Colors custom Dialog:
B4X:
#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
Last edited: