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

FrankBerra

Active Member
Licensed User
Longtime User
After upgrading to the last version the hint text is not displayed anymore. And also it seems that changing the text alignment and the background color in the designer settings doesn't produce any changes. Am I missing something?
 

Mandrake

Member
Licensed User
Longtime User
Hello need the datepicker in my project but as I can do 'm new to this.
The example does not work :(
 

Attachments

  • erroandroid.jpg
    erroandroid.jpg
    183.5 KB · Views: 230

Jose Luis Barajas

Member
Licensed User
Longtime User
Help with AnotherDatePicker in CustomListView

Hi

I like to add this control on customlisvtiew,

When compile my project I get this error

B4A version: 5.80
Parsing code. (0.23s)
Compiling code. (0.31s)
Compiling layouts code. (0.01s)
Generating R file. (0.06s)
Compiling debugger engine code. (1.17s)
Compiling generated Java code. Error
B4A line: 719
Dim tDatePicker As AnotherDatePicker = p.GetView(
javac 1.7.0_55
src\b4a\docucad\enter\code.java:1451: error: inconvertible types
_tdatepicker = (b4a.docucad.enter.anotherdatepicker)(_p.GetView(_idx_datepicker).getObject());
^
required: anotherdatepicker
found: View


The line tha kill the process its

Dim tDatePicker As AnotherDatePicker = p.GetView(0)

Please, can help me, I need to include this control on customlistview

Thanks
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel i have a simple question
Where change the top blue color (where is the spinner´s) and the corner radius? i not found this.

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


On the designer i found only background, select and highlighted color.
And on the class code i dont found any RGB, blue, cyan etc..


thx
 

Wolli013

Well-Known Member
Licensed User
Longtime User
'Spinner Hintergrundfarbe setzen

B4X:
Dim ActionbarFarbe As Int = -16729601
   Years.DropdownBackgroundColor =  ActionbarFarbe
   Months.DropdownBackgroundColor =  ActionbarFarbe
 

JOTHA

Well-Known Member
Licensed User
Longtime User
You can use:
B4X:
DateTime.DateFormat = DateTime.DeviceDefaultDateFormat
Sorry ... that causes a NumberFormatException: Invalid double: "invalid date"
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
Error: Invalid value: n. Chr.20160830 000000
dateutils_setdateandtime (java line: 426)
java.lang.NumberFormatException: Invalid double: "invalid date"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.initialParse(StringToReal.java:94)
at java.lang.StringToReal.parseDouble(StringToReal.java:282)
at java.lang.Double.parseDouble(Double.java:301)
at b4a.example.dateutils._setdateandtime(dateutils.java:426)
at b4a.example.dateutils._setdate(dateutils.java:390)
at b4a.example.anotherdatepicker._selectday(anotherdatepicker.java:406)
at b4a.example.anotherdatepicker._setdate(anotherdatepicker.java:426)
at b4a.example.anotherdatepicker._addtoactivity(anotherdatepicker.java:146)
at b4a.example.main._activity_create(main.java:328)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
java.lang.NumberFormatException: Invalid double: "invalid date"

The original code is
B4X:
DateTime.DateFormat = "GGyyyyMMdd"
... but why is it not possible to use
B4X:
DateTime.DateFormat = "dd.MM.yyyy"

How can I get the correct result of the Dateformat for today in Germany = "30.08.2016" in Label1.Text?
 

DonManfred

Expert
Licensed User
Longtime User
Error: Invalid value: n. Chr.20160830 000000
Was ist denn das für ein Datumsformat??? Wo kommt das her in dieser Form?

but why is it not possible to use
Warum sollte das nicht gehen?
B4X:
    DateTime.DateFormat =    "dd.MM.yyyy"   
    Dim heute As Long = DateTime.DateParse("19.12.1968")
    Log(DateTime.Date(heute))
 
Last edited:

JOTHA

Well-Known Member
Licensed User
Longtime User
Error: Invalid value: n. Chr.20160830 000000
Was ist denn das für ein Datumsformat??? Wo kommt das her in dieser Form?


Warum sollte das nicht gehen?
B4X:
    DateTime.DateFormat =    "dd.MM.yyyy"  
    Dim heute As Long = DateTime.DateParse("19.12.1968")
    Log(DateTime.Date(heute))
Das wüßte ich auch gerne ... es ist wohl das Ergebnis von DateTime.DateFormat = "GGyyyyMMdd"
In diesem Datum sehe ich 2016.08.30 + Uhrzeit 00:00:00 (heutiges Datum um 00:00:00 Uhr)

Mit deinem Code kommt diese Fehlermeldung:
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
19.12.1968
Error: Invalid value: n. Chr.20160830 000000
dateutils_setdateandtime (java line: 431)
java.lang.NumberFormatException: Invalid double: "invalid date"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
...
 

JOTHA

Well-Known Member
Licensed User
Longtime User
Falsch!

DAS ist der Output

** Activity (main) Create, isFirst = true **
19.12.1968

Die Fehlermeldung kommt von einem anderen Code.

Yes thats right, the error message ist the result of that code:
B4X:
Public Sub SetDateAndTime(Years As Int, Months As Int, Days As Int, Hours As Int, Minutes As Int, Seconds As Int) As Long
   
    Dim df = DateTime.DateFormat, tf = DateTime.TimeFormat As String
    DateTime.DateFormat = "GGyyyyMMdd"  '-- Original --   
    DateTime.TimeFormat = "HHmmss"
    Dim d As String = Format(Abs(Years), 4) & Format(Months, 2) & Format(Days, 2)
    d = GetEra(Years < 0) & d
    Dim t As String = Format(Hours, 2) & Format(Minutes, 2) & Format(Seconds, 2)
   
    Try
        Dim ticks As Long = DateTime.DateTimeParse(d, t)
    Catch
        DateTime.DateFormat = df
        DateTime.TimeFormat = tf
            Log("--> Error: Invalid value = Fehler: ungültiger Wert " & d & " " & t)
        Return "--> invalid date = ungültiges Datum" + 1 'hack to throw an error
    End Try
   
    DateTime.DateFormat = df
    DateTime.TimeFormat = tf
        Log("Datum: "&df&" - Uhrzeit: "&tf&"")
    Return ticks

Only the DateTime.DateFormat = "GGyyyyMMdd" is alowed.
This generates the Error: Invalid value: n. Chr.20160830 000000, if you change DateFormat the into DateTime.DateFormat = "dd.MM.yyyy"
 

tiziana.tinnirello

Member
Licensed User
Longtime User
ADP in debug mode works well, in release mode does not show nothing. Help !

EDIT: Solved, moved load layout in Activity_Resume with IsInizialized check
 
Last edited:

daveinhull

Active Member
Licensed User
Longtime User
HI,

Quick question which I can't seem to find any earlier reference to; how can I detect when 'anotherdatepicker' loses focus?

Appreciate any help

Thanks
Dave
 
Status
Not open for further replies.
Top