Android Code Snippet SD: DateDialog (Calendar Picker)

New Class: DateDialog (Calendare Picker)

Methods:
  • Initialize (Myactivity As Activity, Date As Long)
  • SetDate(Date As Long)
  • Show(Title As String)
Properties:
  • DateSelected As Long (Only read)


Find alternative Code on Post#8

I have updated the code so it is possible to set the design you start with the current date (DateTime.Now)

1.png
 

Attachments

  • 2.png
    2.png
    40.4 KB · Views: 2,038
  • DateDialog.zip
    12.6 KB · Views: 1,012
Last edited:

DonManfred

Expert
Licensed User

sn_nn

Member
Licensed User
Android 7.0 - Works fine
Android 4.1.2 - can not set previous Year then 1980. For example: if i select 1974 year, dialog will set 1980! Any help?
 

Star-Dust

Expert
Licensed User
Android 7.0 - Works fine
Android 4.1.2 - can not set previous Year then 1980. For example: if i select 1974 year, dialog will set 1980! Any help?
Could it be a device setting?
I will test on old devices, but it may only be a problem for the device you use
 

sn_nn

Member
Licensed User
Yes, It seems true! it was HighScreen Boost (4.1.2). Ten minutes ago i tried Highscreen Boost 2 (4.1.2) and everything is working correctly!!! I think - it's some bug in firmware of phone... Thank you, Star-Dust!
 

ilan

Expert
Licensed User
The Week starts at Monday and ends on Saturday, Sunday


Montag (1)
Dienstag (2)
Mittwoch (3)
Donnerstag (4)
Freitag (5)
Samstag (6)
Sonntag (7)

so the day in the middle of the week is Donnerstag but why is Mittwoch called Mittwoch (German translation: Mitte der Woche) middle of the week :p
 

netsistemas

Active Member
Licensed User
Monday first day, great.
This is my code
B4X:
private Sub GetFechaControl(Control As B4XFloatTextField)
    Dim I As Long
    Try
        Dim Im As IME
        Im.HideKeyboard
        Log(DateTime.DateFormat)
        D.Initialize(Activity, DateTime.Now)
        D.RedSaturday=1
        D.RedSunday=1
        D.StartOnMonday=True
        I=D.Show("Select Date")
        If I=DialogResponse.POSITIVE Then
            'ToastMessageShow(DateTime.GetDayOfMonth(D.DateSelected) & "-" & DateTime.GetMonth(D.DateSelected) & "-" & DateTime.GetYear(D.DateSelected),True)
        
            Control.Text = modGeneral.DateE2( d.DateSelected )
        Else
            'ToastMessageShow("Don't selected",False)
        End If
        Log(DateTime.DateFormat)
    
            
    Catch
        Log(LastException)
    End Try
    
End Sub

and execute this funcion in B4XFloatTextFields on focus (is not perfect, but easy solucion).
May be, in future, b4xfolattextfields have a date editor internal.

B4X:
Sub B4Fecha_FocusChanged (HasFocus As Boolean)
    If HasFocus Then
        GetFechaControl(Sender)
    End If
End Sub

before this code i used DateTemplate As B4XDateTemplate
 

Star-Dust

Expert
Licensed User
Monday first day, great.
This is my code
B4X:
private Sub GetFechaControl(Control As B4XFloatTextField)
    Dim I As Long
    Try
        Dim Im As IME
        Im.HideKeyboard
        Log(DateTime.DateFormat)
        D.Initialize(Activity, DateTime.Now)
        D.RedSaturday=1
        D.RedSunday=1
        D.StartOnMonday=True
        I=D.Show("Select Date")
        If I=DialogResponse.POSITIVE Then
            'ToastMessageShow(DateTime.GetDayOfMonth(D.DateSelected) & "-" & DateTime.GetMonth(D.DateSelected) & "-" & DateTime.GetYear(D.DateSelected),True)
       
            Control.Text = modGeneral.DateE2( d.DateSelected )
        Else
            'ToastMessageShow("Don't selected",False)
        End If
        Log(DateTime.DateFormat)
   
           
    Catch
        Log(LastException)
    End Try
   
End Sub

and execute this funcion in B4XFloatTextFields on focus (is not perfect, but easy solucion).
May be, in future, b4xfolattextfields have a date editor internal.

B4X:
Sub B4Fecha_FocusChanged (HasFocus As Boolean)
    If HasFocus Then
        GetFechaControl(Sender)
    End If
End Sub

before this code i used DateTemplate As B4XDateTemplate
It actually started before XUI and resumable subs. Now I would do it differently by including these two elements
 

netsistemas

Active Member
Licensed User
In my projects, I found I used this kind of classes, but when turning the phone, the months with 6 weeks (like August 2020), it does not look correctly. After consulting EREL with good judgment, he made me use XUI and everything worked perfectly, but the first day of the week is SUNDAY. Now, that my application does not allow turning the phone, I do not have the program for the number of weeks, and on top I can put Monday as the first day of the week. If XUI ever allows MONDAY as the first day, I will return to XUI, as I consider that it is the most correct.
 
Top