Android Question [B4XPreferencesDialog] App crash when editing date in a DateItem, unparsable date format

Vulcano Team Software

New Member
Licensed User
Hi,
I was looking for a nice dialog to use for a form asking the user to input both the date and the time of its order, and I step upon the library in the title. Sadly I never managed to get the date field to work. The App crash, and looking at the logs this is what I get:
I supposed the problem was the Datetime format I was using, but even setting the platform default I keep getting the same error.
This is the code that should initialize and show the dialog, I left comments in code to show the many tries I done to get it work
B4X:
public Sub dialogo_data()
    Dim dialogo As PreferencesDialog
    Dim output As Map
    Dim time_op As String = DateTime.DateFormat
'   
    DateTime.DateFormat = "yyyy-MM-dd"
    'DateTime.DateFormat = DateTime.DeviceDefaultDateFormat
    'DateTime.TimeFormat = DateTime.DeviceDefaultTimeFormat
'    time_op.Add("24")
    output.Initialize
    dialogo.Initialize(Activity, "test", Activity.Width *0.7, Activity.Height *0.6)
    dialogo.LoadFromJson(File.ReadString(File.DirAssets, "test.json"))
'    dialogo.DateTemplate.Initialize
'    dialogo.DateTemplate.FirstDay = 1
'    dialogo.DateTemplate.Date = DateTime.Now
'    dialogo.AddDateItem("data", "data ora")
'    dialogo.AddExplanationItem("","trololoo", "ahsdjsjaj")
'    dialogo.AddTimeItem("tempo", "tempo_ora")
'    dialogo.SetOptions("tempo", time_op)
    
    Wait For (dialogo.ShowDialog(CreateMap(), "OK", "CANCEL")) Complete(Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("data: " & output.Get("data_item"))
        Log("tempo: " & output.Get("time_item"))
    End If
    'DateTime.DateFormat = time_op
End Sub

We are using B4A version 11.0 and B4XPreferencesDialog version 1.74
 

josejad

Expert
Licensed User
Longtime User
Software Development Manager don't let me distribute the whole source for any reason
Can you reproduce it in a small project?
Create a new project, add the B4XPreferencesDialog and test it. If you get the error, upload it

 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I guess I will need to look to an alternative solution.
You don't need to look to an alternative. PreferenceDIalog works
Here is a complete working example based on your code. You can make a stand alone project and test:
B4X:
public Sub dialogo_data() 
    Dim dialogo As PreferencesDialog
    Dim output As Map
    Dim time_op As String = DateTime.DateFormat
    DateTime.DateFormat = "yyyy-MM-dd"
    output.Initialize
    dialogo.Initialize(Activity, "test", Activity.Width *0.7, Activity.Height *0.6)
    dialogo.AddDateItem("data_item", "data ora")
    dialogo.AddTimeItem("time_item", "tempo_ora")
    output =CreateMap("data_item":Null, "time_item": Null)
    Wait For (dialogo.ShowDialog(output, "OK", "CANCEL")) Complete(Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim d As Long =output.Get("data_item")
        Log($"My string Date: ${DateTime.Date(d)}"$)  'exple:My string Date: 2021-11-20
                
        Dim t As Period =output.Get("time_item")
        Log($"String Time: $2.0{t.Hours}:$2.0{t.Minutes}"$)  'exple: String Time: 19:33
    End If
    DateTime.DateFormat = time_op
End Sub
 
Upvote 1

Vulcano Team Software

New Member
Licensed User
I tested it in a new clean project and it works. I suspect the problem is a bad use of DateTime.dateFormat overall in the main project. Thx all for the replies.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…