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,740
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Been looking for a good alternative to the date dialog as that seems to go all wrong looking when target sdk is high e.g. 17
 

barx

Well-Known Member
Licensed User
Longtime User
I would just like to post an 'in use' pic of this date picker in action. I like this class and it has helped solve my issue with the date dialog available in the dialogs library. I have made s few UI tweak (but that is the joy of classes, right?)

datepicker.png

Thanks Erel
 

barx

Well-Known Member
Licensed User
Longtime User
I just want to check that it works good in a couple more devices then yes, of course I will upload it. I didn't change alot to be honest. Just a couple of tweaks.
 

barx

Well-Known Member
Licensed User
Longtime User
As promised here is my edit (See attached below). Please note that I only edited a few minor UI things, nothing special or functional.

A few of the colors are slightly different to my screenshot, mainly due to, the app I posted screenshot from uses a Custom Light theme, so default texts are dark. Applying that to the sample would just complicate matters.

Anybody that uses Erel original class files, one thing I would add to the DatePicker designer layout script is:

Add
B4X:
Base.Height = Min(300dip, 100%y)

Just after
B4X:
AutoScaleAll

If Erel agrees with this, maybe he will update the original for those that don't read past post #1 :cool:
On my phone 480x800 I found that the bottom of the date picker would be cropped slightly in landscape mode. Adding the above line solves that issue.

Updated to reflect Erels update to DateUtils (now v1.03)

Thanks again Erel, great class.
 

Attachments

  • AnotherDatePicker_BarxEdit.zip
    13.9 KB · Views: 1,737
Last edited:

NJDude

Expert
Licensed User
Longtime User
NICE!!

However, there are some issues:

1- Today is March 29th, and I don't see that date HERE (March has 31 days)

2- Tapping on the TODAY button at the button, brings the right date to the label, however the "blank square" still remains.

3- If you tap on March 28, the "blank square" goes away, but, tapping on the TODAY button brings it back.

4- There are other months containing the wrong number of days, check December 2013 for example.

I've tried that on 4 different devices, same deal.
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
Same thing on both, the original and the modified.

These are the results (2013):

Jan: OK
Feb: OK
Mar: WRONG
Apr: OK
May: WRONG
Jun: OK
Jul: WRONG
Aug: OK
Sep: OK
Oct: WRONG
Nov: OK
Dec: WRONG
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Good. I believe that I found the problem. Please update DateUtils.NumberOfDaysInMonth with this code and test it again:
B4X:
Public Sub NumberOfDaysInMonth(Month As Int, Year As Int) As Int
   Dim Ticks As Long = SetDate(Year, Month, 1)
   Dim nextMonth As Long = DateTime.Add(Ticks, 0, 1, 0)
   Dim res As Int =  Round((nextMonth - Ticks) / DateTime.TicksPerDay)
   Return res
End Sub
 
Status
Not open for further replies.
Top