andyr00d Member Licensed User Longtime User Apr 13, 2020 #1 Hello, I'm struggling to set a default time for a prefdialog time field, I understand that it must be of type period however I've tried the below simple implementation and it's not crashing, but it's also not setting the time (it's showing 12 00 AM by default in the field). B4X: Copy Dim time As Period time.Initialize time.Hours = 11 time.Minutes = 2 Dim ls As List ls.Initialize ls.Add(time) prefdialog.SetOptions("4", ls) The output of time is: [Days=0, Hours=11, IsInitialized=true, Minutes=2, Months=0, Seconds=0, Years=0] I thought this would set it to be "11 02 AM" but it's not working, any ideas?
Hello, I'm struggling to set a default time for a prefdialog time field, I understand that it must be of type period however I've tried the below simple implementation and it's not crashing, but it's also not setting the time (it's showing 12 00 AM by default in the field). B4X: Copy Dim time As Period time.Initialize time.Hours = 11 time.Minutes = 2 Dim ls As List ls.Initialize ls.Add(time) prefdialog.SetOptions("4", ls) The output of time is: [Days=0, Hours=11, IsInitialized=true, Minutes=2, Months=0, Seconds=0, Years=0] I thought this would set it to be "11 02 AM" but it's not working, any ideas?
Erel B4X founder Staff member Licensed User Longtime User Apr 13, 2020 #2 There is a conceptual mistake here. Default values are set in the Data map. The map that is passed to PrefDialog.Show. Upvote 0
There is a conceptual mistake here. Default values are set in the Data map. The map that is passed to PrefDialog.Show.
andyr00d Member Licensed User Longtime User Apr 13, 2020 #3 But that map is created via LoadFromJson, and I don't think the value can be set within the json file can it? Upvote 0
But that map is created via LoadFromJson, and I don't think the value can be set within the json file can it?
Erel B4X founder Staff member Licensed User Longtime User Apr 13, 2020 #4 No. No. The json file creates the template. The data map stores the initial values and the set values. Upvote 0
No. No. The json file creates the template. The data map stores the initial values and the set values.
josejad Expert Licensed User Longtime User Apr 13, 2020 #5 andyr00d said: But that map is created via LoadFromJson Click to expand... No, with LoadFromJson you create the "form" layout. Review again the B4XPreferencesDialog, when it says: 2. Call ShowDialog and pass the data map. It can be an empty map or a map where some of the fields are already set. B4X: Code: Copy 'Options1 is a Map object Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int) If Result = xui.DialogResponse_Positive Then PrintOptions(Options1, TextArea1) End If The data map will be updated when the user clicks on the OK button. So Options1 is the map where you get the answer, but if it's populated with data, it will be shown as filled in the dialog. That's where you have to set you default time. Upvote 0
andyr00d said: But that map is created via LoadFromJson Click to expand... No, with LoadFromJson you create the "form" layout. Review again the B4XPreferencesDialog, when it says: 2. Call ShowDialog and pass the data map. It can be an empty map or a map where some of the fields are already set. B4X: Code: Copy 'Options1 is a Map object Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int) If Result = xui.DialogResponse_Positive Then PrintOptions(Options1, TextArea1) End If The data map will be updated when the user clicks on the OK button. So Options1 is the map where you get the answer, but if it's populated with data, it will be shown as filled in the dialog. That's where you have to set you default time.