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:

JTmartins

Active Member
Licensed User
Longtime User
DateUtils.TicksToStrings internally calls DateTime.Date(...) & " " & DateTime.Time(...).

You should use:
B4X:
Label1.Text = DateTime.Date(Date)

Thanks Erel. It does work and problem solved.

But I'm so curious of the reason that the initial code gave one result in tablet and a diferent result in the phone, being that the only difference is OS version. All other settings where the same.

Living and learning.
 

dibesw

Active Member
Licensed User
Longtime User
HI,
I'm trying this DataPicker.
When I choose a day, program hide datapicker and write data into label,
but there is a possibility that it run event automatically in activity then I can sub any routine?
(Excuse my bad english).
Thanks!
 

dibesw

Active Member
Licensed User
Longtime User
where should I put this?
I put this sub in MAIN...
B4X:
Sub ADP_Closed (Cancelled As Boolean, Date As Long)
  Msgbox("CLOSED!!!","")
  Log("Cancelled = " & Cancelled & ", Date = " & DateUtils.TicksToString(Date))
End Sub
...but nothing happens
 

Steve Miller

Active Member
Licensed User
Longtime User
Nice control. I came across a problem in displaying the month. It is truncating long month names. February is only showing as "Februa". I tried to adjust the Months spinner to be 160 width, but that makes no difference. What can I do to fix this so it doesn't truncate?
 

Steve Miller

Active Member
Licensed User
Longtime User
I'd prefer to increase the spinner size, but it's not having any effect. I opened the designer and selected datepicker.bal and changed the Months spinner width to 200, and it's not changing the size. I also deleted the datepicker from the page and added it again after increasing the width. Still no luck. Is there more that I need to do, that I'm missing?
 

JohnC

Expert
Licensed User
Longtime User
The problem happens because there is a call to AddToActivity in DesignerCreateView that is done with CallSubDelayed. It must use CallSubDelayed because it is not possible to load a layout file while a file is being loaded.

The solution is to use CallSubDelayed in your code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   CallSubDelayed(Me, "SetDate")
End Sub
 
Sub SetDate
   ADP.SetDate(DateTime.Now, True)
End Sub

I am adding the ADP to an activity using the designer, so I am not adding it or initializing it via code.

Upon loading of the activity, I want to pre-set the date of the ADP, but when I try to use the ".SetDate" at the end of the Activity_Create sub, it gives a "java.lang.RuntimeException: Object should first be initialized (Label)." error.

So, I tried using your CallSubDelayed method above and still I get that error.

How can I assign a value to the ADP when the activity is loaded without getting an error because the targetLabel is not initialized yet?
 

JohnC

Expert
Licensed User
Longtime User

It turned out that I was displaying a msgbox in the activity_create BEFORE I was doing the .setdate function lower in that same sub and for some reason the act of displaying that msgbox caused the targetLabel to not be initialized. When I removed the msgbox statement, the error went away.
 

Xardoz

Member
Licensed User
Longtime User
Sorry for a stupid question....

I am very new to B4A and am trying to use this library in my project.

I have referenced DateUtils v1.05
I am running: B4A 3.20

When I enter Dim ADP As in the Globals of the sub pane, I do not get AnotherDatePicker in the intelisense

Thank You in Advance

ps:
The simplest way to add it is with the designer. You should add a CustomView and then set its type.
I tried this and AnotherDatePicker does not show up in the designer
 

Steve Miller

Active Member
Licensed User
Longtime User
No matter what I do, it will not widen the month. I set the lblSelectedDay to left = 150. I see the label move to the right. But, when I click on the scripts tab, it moves back to center.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Xardoz ADP is a class module. You need to add it to your project (Project - Add Existing Module).

No matter what I do, it will not widen the month. I set the lblSelectedDay to left = 150. I see the label move to the right. But, when I click on the scripts tab, it moves back to center.
Go over the script. You will see that the label is layout is set in the script.
 

Steve Miller

Active Member
Licensed User
Longtime User
When the datepicker loads, it's blank. If a date is not selected the textbox remains blank, but when executing the GetDate method, it returns today's date. If a date isn't selected, how do I return null? I'm saving the values in a database and if a date is not selected, I need to save a null value, not the current date.
 
Status
Not open for further replies.
Top