Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private PrefDialog1 As PreferencesDialog
Private ProductName As String = "Default"
Private Category As String = "Toys"
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
CreateDialog1
End Sub
Private Sub B4XPage_Resize(Width As Int, Height As Int)
If PrefDialog1.IsInitialized And PrefDialog1.Dialog.Visible Then PrefDialog1.Dialog.Resize(Width, Height)
End Sub
Private Sub BtnShow_Click
ShowDialog1
End Sub
Private Sub CreateDialog1
PrefDialog1.Initialize(Root, "Product", 300dip, 300dip)
PrefDialog1.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40)
PrefDialog1.Dialog.TitleBarHeight = 50dip
PrefDialog1.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
PrefDialog1.SetEventsListener(Me, "PrefDialog1") '<-- must add to handle events.
End Sub
Private Sub ShowDialog1
PrefDialog1.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225)
PrefDialog1.Title = "Product"
Dim Item As Map = CreateMap("Product Name": ProductName, "Category": Category)
Dim sf As Object = PrefDialog1.ShowDialog(Item, "CONFIRM", "CANCEL")
Sleep(0)
PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
Wait For (sf) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
'Log(Item) ' don't confuse, you need the returned ProductName, not the map
Log($"Product Name: ${ProductName}"$) '<--- default if no value specified
End If
End Sub
Sub PrefDialog1_IsValid (TempData As Map) As Boolean
ProductName = TempData.GetDefault("Product Name", "Default") '<-- use GetDefault as mentioned in post #2
Category = TempData.GetDefault("Category", "Toys")
Return True
End Sub