B4J Tutorial [ABMaterial] DateTimePicker Extented for Weeks (1.20)

The ABMDateTimePicker has, next to date and time selection now also week selection. I've searched some time to find a good one, but didn't so I decided to write it myself. Looks like a great addition to the framework.

weekpicker.png


Usage:

B4X:
Dim mydate3 As ABMDateTimePicker
    Dim NewDate As Long = DateTime.Now
    mydate3.Initialize(page, "1", ABM.DATETIMEPICKER_TYPE_WEEK, NewDate, "Pick a date and time", "")
    mydate3.CancelText = "Back"
    mydate3.PickText = "OK"
    mydate3.TodayText = "This week"
    mydate3.Language = "nl"
    mydate3.ReturnDateFormat = "MM/DD/YYYY"   ' <--- see demo source code for settings
    mydate3.ReturnTimeFormat = "" ' <--- see demo source code for settings
    mydate3.FirstDayOfWeek = 1
    mydate3.WeekText = "Week"  
    page.CellR(1,1).AddArrayComponent(mydate3, "arrdate") '    <---
 

Don Oso

Active Member
Licensed User
Longtime User
Hi , Im trying to get datetime from mysql database and put the data into ABMDateTimePicker using the common way shown in the examples

B4X:
Dim mydate3 As ABMDateTimePicker = page.Component("mydate3")
                   
Dim bd As String= user.Get("birthdate")
       
mydate3.SetDateISO(bd)
           
mydate3.Refresh

' This Code get  Erro java.lang.NullPointerException , because   "page.component("mydate3")" returns NULL.

Thanks!
 

Don Oso

Active Member
Licensed User
Longtime User
Thanks for your fast answer i add the datetimepicker in the BuildPage Method
B4X:
public Sub BuildPage()   
...
...
....
    Dim mydate3 As ABMDateTimePicker
    Dim NewDate As Long = DateTime.DateParse("01/01/1990")
    mydate3.Initialize(page, "1", ABM.DATETIMEPICKER_TYPE_DATE, NewDate, "Ingrese Fecha Nacimiento", "")
    mydate3.CancelText = "Volver"
    mydate3.PickText = "OK"
    mydate3.TodayText = "Hoy"
    mydate3.Language = "es"
    mydate3.ReturnDateFormat = "MM/DD/YYYY"   ' <--- see demo source code for settings
    mydate3.ReturnTimeFormat = "HH:mm"        ' <--- see demo source code for settings
    mydate3.FirstDayOfWeek = 0
    'mydate3.ClickThrough = True  <--- set to true if, when the user makes a selection, the ok action should be triggered.
    page.Cell(5,2).AddArrayComponent(mydate3, "arrdate") '    <--- showing adding as an array
...
...
...
End Sub
 

alwaysbusy

Expert
Licensed User
Longtime User
Have you refreshed the page (in Chrome, press F12, go to the network tab, disable caching, press F5). If this does not work, would you mind emailing me ([email protected]) the full code for this page? From what I see it should work, but maybe something specific is in your code.

Just a side note I've seen myself this weekend on F5 and refreshing.

While rewriting the reconnect engine, I've noticed something very weird with refreshing a page. Pressing F5 in Chrome has different behaviours depending on the version and if the console is open:

Chrome 53.xxx + console open (F12): The page was reloaded and it passed through the ABMSessionCreator in B4J (CORRECT)
Chrome 53.xxx + console closed: The page was reloaded and it passed through the ABMSessionCreator in B4J (CORRECT)

Chrome 54.xxx + console open (F12): The page was reloaded and it passed through the ABMSessionCreator in B4J (CORRECT)
Chrome 54.xxx + console closed: No idea if the page was reloaded and it did NOT pass through the ABMSessionCreator in B4J (WRONG)

This raises some concern as ABMaterial heavily relies on Refreshing a page in the browser working correctly. I hope I have some workaround for this problem in the the Reconnect engine in 2.01. I'm currently updating the feedback app and the demo app to this new reconnect system. (It demands some changes in WebSocket_Connected, Page_ParseEvent and the ABMSessionCreator class. Don't worry, not that big and I've tried to make it as simple as possible).
 

alwaysbusy

Expert
Licensed User
Longtime User
I can't run your app,n but I do see the id of the data component is not "mydate3" but "1" and it is added as an arraycomponent.

so change:

B4X:
mydate3.Initialize(page, "1", ABM.DATETIMEPICKER_TYPE_DATE, NewDate, "Ingrese Fecha Nacimiento", "")

to:

B4X:
mydate3.Initialize(page, "mydate3", ABM.DATETIMEPICKER_TYPE_DATE, NewDate, "Ingrese Fecha Nacimiento", "")

and change:

B4X:
page.Cell(5,2).AddArrayComponent(mydate3, "arrdate")

to:

B4X:
page.Cell(5,2).AddComponent(mydate3)
 

Don Oso

Active Member
Licensed User
Longtime User
Hi thanks !

My code ... its your code :D ... I use the ABMDateTimePicker in three stages or events

1) when the user click sidebarmenu to access the page with his profile data ..

First the Page call BuildPage() ' Mimic from your AMBfeedback app.

With this code:

B4X:
.......
......
    Dim mydate3 As ABMDateTimePicker
    Dim NewDate As Long = DateTime.DateParse("01/01/1990")
    mydate3.Initialize(page, "1", ABM.DATETIMEPICKER_TYPE_DATE, NewDate, "Pick a date and time", "")
    mydate3.CancelText = "Volver"
    mydate3.PickText = "OK"
    mydate3.TodayText = "Hoy"
    mydate3.Language = "es"
    mydate3.ReturnDateFormat = "MM/DD/YYYY"   ' <--- see demo source code for settings
    mydate3.ReturnTimeFormat = "HH:mm"        ' <--- see demo source code for settings
    mydate3.FirstDayOfWeek = 0
    'mydate3.ClickThrough = True  <--- set to true if, when the user makes a selection, the ok action should be triggered.
    page.Cell(5,2).AddComponent(mydate3) '    <--- showing adding as an array    I Change this part like you told me 
.......
.......


2) then CargaUsuario() ( LoadUser in spanish) this method query the database (Mysql)

B4X:
......
.....

        Dim SQL As SQL = DBM.GetSQL
       
        ActiveUserId = ws.Session.GetAttribute("UserID") 
       
        Dim users As List = DBM.SQLSelect(SQL, "SELECT * FROM Users WHERE idusers=?", Array As String(ActiveUserId))
        If users.Size > 0 Then
            Dim user As Map = users.Get(0)

.....
.....
....
            Dim mydate3 As ABMDateTimePicker = page.Component("mydate3") '' <---- this Fail i Get "Null"

            Dim fecnac As String = user.Get("birthdate")

            mydate3.SetDateISO(fecnac)   

            'mydate3.Refresh
                   

        End If
       
        DBM.CloseSQL(SQL)

......
.......
.....
debug2.png

In the Debugger you get that


crash.png


This Code fills my page with user profile data . the user can change his information and Update de info calling another method.

Thanks for your Help

Javier.
 

Don Oso

Active Member
Licensed User
Longtime User
I found !! the Bug :D:D

The problem was in the ABMDateTimePicker.initialize(page,"1" <-- Should be the name of the object Created "mydate3" .

like this

B4X:
    Dim mydate3 As ABMDateTimePicker
    Dim NewDate As Long = DateTime.DateParse("01/01/1990")
    mydate3.Initialize(page, "mydate3", ABM.DATETIMEPICKER_TYPE_DATE, NewDate, "Pick a date and time", "")
    mydate3.CancelText = "Volver"
    mydate3.PickText = "OK"
    mydate3.TodayText = "Hoy"
    mydate3.Language = "es"
    mydate3.ReturnDateFormat = "MM/DD/YYYY"   ' <--- see demo source code for settings
    mydate3.ReturnTimeFormat = "HH:mm"        ' <--- see demo source code for settings
    mydate3.FirstDayOfWeek = 0
    'mydate3.ClickThrough = True  <--- set to true if, when the user makes a selection, the ok action should be triggered.
    page.Cell(5,2).AddComponent(mydate3) '

This code works fine when you try to retrieve date from mysql and put that datetime field into ABMDateTimePicker

Now this Works
B4X:
' this code retrieve date from an List object loaded with Mysql records.
'

            Dim mydate3 As ABMDateTimePicker = page.Component("mydate3")
            Dim fecnac As String = user.Get("birthday")
            mydate3.SetDateISO(fecnac)   
            mydate3.Refresh

DateTimePicker.png


this happend to me because i copy the code that's come in to the demo App in Abmaterial 1.22. lib

bugDemoCode.jpg


Thanks for your help Alain ... Great Lib/Framework!

Javier.
 
Top