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

Erel

B4X founder
Staff member
Licensed User
Longtime User
The selected date is set in SelectDay sub. This sub is called when the ADP is created. You can add a counter and increment it in this sub.

Now when you return the date with GetDate check the value of this counter. If it is 1 (which means that the user hasn't selected any date) then return 0. In your program you can replace the 0 with null.
 

Steve Miller

Active Member
Licensed User
Longtime User
That would work if I used the date control once, but I have it in use 7 times. Being the code is shares, I wouldn't know which date control was actually used.
 

JohnC

Expert
Licensed User
Longtime User
I just created another new activity using the designer and placed this DatePicker on it. Now everytime the activity loads it gives the same "Object should be initialized (Label)" error.

What am I doing wrong?

Here is my startup code in the activity:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
 
    Dim Table2 As Table  
  
    Private cmdLeft As Button
    Private cmdRight As Button
    Private dtpWeekday As AnotherDatePicker
    Private pnlWeekly As Panel
 
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("weekly")
 
    Activity.Title="Weekly Report"
  
    Table2.Initialize(Me, "Table2", 10, Gravity.CENTER_HORIZONTAL, False)
    Table2.CellAlignment = Bit.OR(Gravity.LEFT, Gravity.CENTER_VERTICAL)
    Table2.HeaderColor = Colors.DarkGray
    Table2.HeaderTextColor = Colors.White
    Table2.TextColor = Colors.Black
    Table2.TableColor = Colors.White
    Table2.AddToActivity(pnlWeekly, 0, 0, pnlWeekly.Width, pnlWeekly.Height)  
    Table2.MultiSelect = False
    Table2.RowColor1 = Colors.White
    Table2.RowColor2 = Colors.White
    Table2.SelectedRowColor = Colors.Yellow
    Table2.SelectedCellColor = Table2.SelectedRowColor
    Table2.setTextSize(Blacktop.JobListFontSize)
  
    Table2.SetHeader(Array As String("Day","Comm","#Chks","Cash","JobsDone","NotDone","Reseals","TotalBill","Miles","Gas"))
    Table2.SetColumnsWidths(Array As Int(200,0,0,0,0,0,0,0,0,0))
 
    CallSubDelayed(Me, "SetDate")
 
End Sub
 
Sub SetDate
 
    dtpWeekday.SetDate(DateTime.Now,True)
  
End Sub
 

JohnC

Expert
Licensed User
Longtime User
OK, now it seems like it's stuck in this loop forever:

B4X:
If waitForAddToActivity Then
    CallSubDelayed3(Me, "SetDate", date, UpdateLabel)
    Return
End If

Because the waitForAddActivity is never set to FALSE - in fact, the log files says this:

Object context is paused. Ignoring CallSubDelayed: AddToActivity

If I remove all the code for the 'Table2' stuff in the Activity_Create, the DTP works.

So, it seems like the Table (which is another class module I download elsewhere in this forum) is causing a problem. I can visually see a 1/2 second delay after the activity loads before the table's columns appear.

How can DTP be assigned a date when the activity is loaded if there are other views that take time to init?
 

JohnC

Expert
Licensed User
Longtime User
The project is too big and would take too long to remove the proprietary code. But I did find a fix by rearranging the code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    Activity.LoadLayout("weekly")
 
    Activity.Title="Weekly Report"
       
    CallSubDelayed(Me, "SetDate")
 
End Sub
 
Sub SetDate
 
    dtpWeekday.SetDate(DateTime.Now,True)
 
    Table2.Initialize(Me, "Table2", 10, Gravity.CENTER_HORIZONTAL, False)
    Table2.CellAlignment = Bit.OR(Gravity.LEFT, Gravity.CENTER_VERTICAL)
    Table2.HeaderColor = Colors.DarkGray
    Table2.HeaderTextColor = Colors.White
    Table2.TextColor = Colors.Black
    Table2.TableColor = Colors.White
    Table2.AddToActivity(pnlWeekly, 0, 0, pnlWeekly.Width, pnlWeekly.Height)   
    Table2.MultiSelect = False
    Table2.RowColor1 = Colors.White
    Table2.RowColor2 = Colors.White
    Table2.SelectedRowColor = Colors.Yellow
    Table2.SelectedCellColor = Table2.SelectedRowColor
    Table2.setTextSize(Blacktop.JobListFontSize)
    Table2.SetHeader(Array As String("Day","Comm","#Chks","Cash","JobsDone","NotDone","Reseals","TotalBill","Miles","Gas"))
  
End Sub
 

stanks

Active Member
Licensed User
Longtime User
how to add this date picker to activity that alreday is designed (i have already all views...need to add this date picker)?
 
Last edited:

jazzzzzzz

Active Member
Licensed User
Longtime User
I don't understand how to add this to my program...
I dont use designer for adding views...i have many views all created by using activity.add view...i don't know understand how to add this without using activity.loadlayout..please help
 

EvgenyB4A

Active Member
Licensed User
Longtime User
It will be complicated to implement a Hebrew DatePicker as there is no built-in Hebrew calendar in the Java API. So you will need to implement the calendar rules yourself.
OK. Thanks for information
 

jazzzzzzz

Active Member
Licensed User
Longtime User
Urgent help needed....This library is not compiling in 3.82 version of b4a please @Erel check this and confirm
 

mmucek

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.
 
Status
Not open for further replies.
Top