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

seardnA

Member
Licensed User
Longtime User
Could anyone post a piece of code on how to use it? I read that it is a class that refers to an activity object, so I cannot use DIM ADP as AnotherDatePicker, but what do I do instead?
Do I read .text from the customview element, but that's a string and not a long?
Do I need to initatize it ?
 
Last edited:

sanjibnanda

Active Member
Licensed User
Longtime User
Could anyone post a piece of code on how to use it? I read that it is a class that refers to an activity object, so I cannot use DIM ADP as AnotherDatePicker, but what do I do instead?
Do I read .text from the customview element, but that's a string and not a long?
Do I need to initatize it ?

i have posted a code here, though it is giving some errors, but may help you to start with. also watch that thread for a possible solution.
 

jaraiza

Active Member
Licensed User
Longtime User
I needed to hide and show the label programmatically, so I added some methods to the class:
B4X:
Public Sub LabelShow
    targetLabel.Visible = True
End Sub

Public Sub LabelHide
    targetLabel.Visible = False
End Sub
So I can call
B4X:
ADP.LabelShow
or
B4X:
ADP.LabelHide

Just my 2 cents ;)
 

seardnA

Member
Licensed User
Longtime User
I get a "java.lang.RuntimeException: Method: setText not found in: b4a.program.anotherdatepicker" when I assign a long value to the editText.Text variable that I use the ADP for.
Where is the error when I assign the value of another variable type long to the edittext.text of the customview element, when ADP itself returns GetDate as Long.

My plan was to either use ADP as input for a date or retrieve and display a stored value.
 

Reinierus

Member
Licensed User
Longtime User
Hi,
I use AnotherDatePicker in my application and when I run the application in debugger it works fine. However, when I compile it as "Release", start app and click button calls cuDatePicker.show get this error:

java.lang.RuntimeException: Object should first be initialized (Panel).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
at anywheresoftware.b4a.objects.ViewWrapper.setVisible(ViewWrapper.java:211)
at DiabetesNotes.LGSoft.com.hr.anotherdatepicker._show(anotherdatepicker.java:476)
at DiabetesNotes.LGSoft.com.hr.anotherdatepicker._lbl_click(anotherdatepicker.java:422)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19330)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

It seems that the sub AddToActivity (called by "CallSubDelayed3(Me, "AddToActivity",act , newLbl)") is never executed. I can not reproduce the error on a clean project. B4A is version 3.82.

I have the same problem. Any idea to solve it?

Thanks,
 

seardnA

Member
Licensed User
Longtime User
I get a "java.lang.RuntimeException: Method: setText not found in: b4a.program.anotherdatepicker" when I assign a long value to the editText.Text variable that I use the ADP for.
Where is the error when I assign the value of another variable type long to the edittext.text of the customview element, when ADP itself returns GetDate as Long.

My plan was to either use ADP as input for a date or retrieve and display a stored value.

Update:

I wrote
B4X:
Sub BtnBirthDate_LongClick
   DateTime.DateFormat = "MM/dd/yyyy"
   p.pBirthdate=ADP.GetDate
End Sub
with p.pBirthdate of type long. This exited with p.pBirthdate = 0
Then I changed the code to
B4X:
Sub BtnBirthDate_LongClick
   DateTime.DateFormat = "MM/dd/yyyy"
    p.pBirthdate = DateTime.Date(ADP.GetDate)
End Sub
with p.pBirthdate of type string.

This time it does not exit, but the value of p.pBirthdate is always 01/01/1970, which equals 0, I assume.

What is it that I do wrong?
Thanks,
 
Last edited:

ducphu

Active Member
Licensed User
Longtime User
Hi Erel,

Can I have this class with all the views are initialized by code, not designer. I would like to customize the layout a bit but unfortunately I'm not goog at using designer so I prefer code :p Thank thank a lot
 

Harish Kumar Arya

Member
Licensed User
Longtime User
There is a bug. If a horizontally moving finger moves past the picker on either side, lblSelectedDay keeps on displaying next/previous days till screen edge is encountered.
How is DaysPanel_Touch returning X value beyond its side margins?
 
Last edited:

John Woodsmall

Active Member
Licensed User
Longtime User
ok...the zip file above is for b4a...not for b4i.
do you have an example of the datepicker with b4i?
the b4a source does not compile.
 

Roberto Cardenas

Member
Licensed User
Longtime User
Hello, @Reinierus could you please post the solution to the problem when the app is compiled in Release mode:
java.lang.RuntimeException: Object should first be initialized (Panel).
Did you forget to call Activity.LoadLayout?​

Thanks a lot,
Robert
 

LucaMs

Expert
Licensed User
Longtime User
The comment of the routine AddToActivity says:

Adds the picker to the ITS parent. ACT can be either an activity or a panel

and given that this routine is public, I suppose if you want to add an ADP thru code you need to call this routine.

If I pass a panel to this routine (ACT parameter), the construction of the ADP takes place at the center of the screen, I think, and then without considering the Panel (the ADP it may event be "invisible", out of the panel).

Am I wrong? How can I place the ADP where I want and with the size I want (via code)?


Thank you
 

tdocs2

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,
Please let me know what is wrong with date dialog.

I know that it does not handle leap years 1900 and 2100, but other than that I have not found any problems. Your comments alerted me to a potential issue in some of my development.

Thank you kindly.

Sandy
 
Status
Not open for further replies.
Top