Android Question Prefdialog set default time

andyr00d

Member
Licensed User
Longtime User
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:
    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?
 

andyr00d

Member
Licensed User
Longtime User
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

josejad

Expert
Licensed User
Longtime User
But that map is created via LoadFromJson
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:
B4X:
'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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…