B4A Library [Class] AnotherDatePicker - A simple "web style" date picker

Status
Not open for further replies.
This is an old version. Latest version is included in XUI Views: https://www.b4x.com/android/forum/threads/100836/#content

AnotherDatePicker is an inline date picker:

SS-2016-02-10_17.26.22.png


The advantage of this class over the built-in dialog (DateDialog from the Dialogs library) is that you can easily customize it as needed.

Most of the layout is created with the visual designer and designer script.

ADP.GetDate returns the selected date.

The months names and days names are based on the device locale.

In order to use this class in your code you should add AnotherDatePicker class, reference DateUtils library and add DatePicker layout file to the Files tab.

Starting from v2.0, ADP should be added as a custom view from the designer:

SS-2016-02-10_17.26.57.png


v2.0 - Better support for visual designer and more configurable options (including first day of week).
v1.11 - Fixes an issue with SetDate that is called before the view is ready.
v1.10 - Adds a Closed event. See the attached example.
 

Attachments

  • AnotherDatePicker.zip
    13.2 KB · Views: 3,764
Last edited:

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
I'm having problems with this class.
I save dates as a string format "dd/MM/yyyy"
When I read it...

B4X:
    Dim sFecha as string
    Dim eFecha as AnotherDatePicker
    DateTime.DateFormat="dd/MM/yyyy"
    sFecha=Cursor1.GetString("fecha")
    If sFecha="" Then  sFecha=DateTime.Date(DateTime.Now)
    eFecha.setdate(DateTime.DateParse(sFecha&" 00:00:00"),True)
    Log(sFecha&" 00:00:00  "&DateTime.DateParse(sFecha&" 00:00:00"))
    Log(sFecha&" "&eFecha.getdate()&" "&DateTime.Date(eFecha.GetDate()))

The resluting log is:
01/07/2015 00:00:00 1435719600000
01/07/2015 0 31/12/1969

eFecha.getdate() = 0! but I see it ok in the activity as 01/07/2015

Whats wrong?

And, how can I HIDE de AnotherDatePicker view?

Thanks
 
Last edited:

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Theres a problem here, it seams that hide and show are from the datepiker itself, the activity where you select the date.
I need to hide/unhide the conteiner, the resulting date.

Using .hide it hides ok but using .show the picker activity appears and the container dont.
 
Last edited:

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Another problem, see image...
I need to warn the user in the activity create... I cant
How can I avoid this error?
When to warn the user using a MsgBox?
 

Attachments

  • errordatepicker.png
    errordatepicker.png
    77.9 KB · Views: 301
  • 2015-07-26-15-52-41.png
    2015-07-26-15-52-41.png
    123.1 KB · Views: 303

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Theres a problem here, it seams that hide and show are from the datepiker itself, the activity where you select the date.
I need to hide/unhide the conteiner, the resulting date.

Using .hide it hides ok but using .show the picker activity appears and the container dont.
and when I use .hide in activity_create or _resume I get an error saying I need to initiate the object and so on...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
and when I use .hide in activity_create or _resume I get an error saying I need to initiate the object and so on
ADP will not be immediately ready due to the way it creates the layout.

I'm not sure that I understand the problem with hiding ADP. However as the source code is available and it is not too complicated I recommend you to go over it and change whatever you need.
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
If the user does not choose any date and you save the date with:
B4X:
DateTime.Date(MyADPdate.GetDate())
the result is today date, even if the user did not touch the date, there are dates that can be left blanked.
how can this be solved?

And if the user choose a date, how can the user "delete" the date, that is leave the date field empty?

Thanks
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Ok, but how can I hide an ADP ?
ADP.hide hides the holder, not the date field
ADP.show shows the holder, not the date field?
Theres no method to hide the traget.
I dont know how to do it.
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Ok, I´ve made it public but how can I hide it?
In my activity ...
B4X:
dim MyADP as AnotherDatepIcker
MyADP. ....
If I type MyADP. I see the same options.
How can I hide MyADP from my activity?
Thanks
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Thanks it works but... when I hide it I get a white zone instead.
Ive tryed seting the color to the activity background color but nothing...
How can I solve this?
 

Attachments

  • 2015-08-24-10-31-47[1].png
    2015-08-24-10-31-47[1].png
    122.9 KB · Views: 260

padvou

Active Member
Licensed User
Longtime User
How can I emulate the ADP.btnCancel_Click by clicking on the back button and then return?
 

LucaMs

Expert
Licensed User
Longtime User
Intercepting the activity keypress:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    Select KeyCode
        Case KeyCodes.KEYCODE_BACK
             ' Do what you want; for example, call the bntCancel_Click
        Case ...
        Case Else
    End Select
 

padvou

Active Member
Licensed User
Longtime User
Intercepting the activity keypress:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    Select KeyCode
        Case KeyCodes.KEYCODE_BACK
             ' Do what you want; for example, call the bntCancel_Click
        Case ...
        Case Else
    End Select

Thank you.
But I only want to close the datepicker when it's shown. If it's not, back key has other functions for my code.
 

LucaMs

Expert
Licensed User
Longtime User
Declare a boolean module variable like DPIsShown and check it on Activity_KeyPress.

B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    Select KeyCode
        Case KeyCodes.KEYCODE_BACK
              If mDPIsShown Then
                    btnCancel_Click
              Else
                 ' Do other
              End If
 
Status
Not open for further replies.
Top