The options work very well in project without database. When I wanted to refresh the options from updated database, the option is not updated.
In attached project, go to "Page 3" from MainPage and click on button "Show Options", the options show 3 items.
Click on button "Add Option" then click on button "Show Options" again.
In attached project, go to "Page 3" from MainPage and click on button "Show Options", the options show 3 items.
Click on button "Add Option" then click on button "Show Options" again.
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private PrefDialog3 As PreferencesDialog
Private FruitList3 As List
End Sub
Public Sub Initialize As Object
Return Me
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("Page3")
CreateDialog
End Sub
Private Sub CreateDialog
PrefDialog3.Initialize(Root, "Dialog", 300dip, 300dip)
PrefDialog3.LoadFromJson(File.ReadString(File.DirAssets, "template_fruit.json"))
RefreshList
End Sub
Private Sub ShowDialog (Fruits As Map)
Dim sf As Object = PrefDialog3.ShowDialog(Fruits, "OK", "CANCEL")
Wait For (sf) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
xui.MsgboxAsync("You have chosen " & Fruits.Get("Favourite"), "Favourite Fruit")
Main.MyFavourite = Fruits.Get("Favourite")
End If
End Sub
Private Sub BtnShowOptions_Click
Dim Fruits As Map = CreateMap("Favourite": Main.MyFavourite)
ShowDialog(Fruits)
End Sub
Private Sub BtnAddOption_Click
Dim BlnFound As Boolean
Dim RS As ResultSet = Main.DB.ExecQuery2($"SELECT Fruit FROM Fruits WHERE Fruit = ?"$, Array As String("Durian"))
Do While RS.NextRow
BlnFound = True
Loop
RS.Close
If BlnFound Then
xui.MsgboxAsync("Durian is already in list", "Duplicate Option")
Else
Main.DB.ExecNonQuery2($"INSERT INTO Fruits (Fruit) SELECT ?"$, Array As String("Durian"))
xui.MsgboxAsync("You have added Durian", "New Option")
RefreshList
End If
End Sub
Private Sub BtnRemoveOption_Click
Dim BlnFound As Boolean
Dim RS As ResultSet = Main.DB.ExecQuery2($"SELECT Fruit FROM Fruits WHERE Fruit = ?"$, Array As String("Durian"))
Do While RS.NextRow
BlnFound = True
Loop
RS.Close
If BlnFound Then
Main.DB.ExecNonQuery2($"DELETE FROM Fruits WHERE Fruit = ?"$, Array As String("Durian"))
xui.MsgboxAsync("You have removed Durian", "Removed Option")
RefreshList
Else
xui.MsgboxAsync("Durian not found in database", "Missing Option")
End If
End Sub
Private Sub BtnClosePage_Click
B4XPages.ClosePage(Me)
End Sub
Private Sub RefreshList
FruitList3.Initialize
Dim RS As ResultSet = Main.DB.ExecQuery($"SELECT Fruit FROM Fruits"$)
Do While RS.NextRow
FruitList3.Add(RS.GetString("Fruit"))
Loop
RS.Close
If PrefDialog3.IsInitialized Then
PrefDialog3.SetOptions("Favourite", FruitList3)
End If
End Sub