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

padvou

Active Member
Licensed User
Longtime User
Declare a boolean module variable like DPIsShown and check it on Activity_KeyPress.
Moreover,
this command: ADP.btnCancel_Click gives me an exception :
B4X:
java.lang.RuntimeException: Object was not initialized.
    at anywheresoftware.b4a.debug.Debug.PushSubsStack(Debug.java:121)
    at uop.unicollect.anotherdatepicker._btncancel_click(anotherdatepicker.java:205)
    at uop.unicollect.main._activity_keypress(main.java:714)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at uop.unicollect.main$HandleKeyDelayed.runDirectly(main.java:224)
    at uop.unicollect.main$HandleKeyDelayed.run(main.java:221)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5584)
    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:1268)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1

when used like this:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
ADP.btnCancel_Click
Return True
end sub
 

padvou

Active Member
Licensed User
Longtime User
See the example in the first post. It already implements this.
Yeah, that was exaclty how I had implemented it, however I declared a different name for the ADP in the designer than the one in the Globals, that's why it was failing..
Dumb mistake of mine..
 

Adilson Jacinto

Active Member
Licensed User
Longtime User
AnotherDatePicker is an inline date picker:

SS-2013-03-21_16.30.05.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 v1.10 the simplest way to add the picker is with the designer. You should add a CustomView and then choose AnotherDatePicker as the custom view type:

SS-2013-05-30_16.14.24.png


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.


Hi,

I cannot find "AnotherDatePicker" option in my custom view, I have added the class and referenced the DateUtils and added DatePicker layout but I can see the class in the dropdown menu
 

Adilson Jacinto

Active Member
Licensed User
Longtime User
1. What happens when you run the example code? Does it work?

2. Check the CustomListView example: https://www.b4x.com/android/forum/t...xible-list-based-on-scrollview.19567/#content ?

Do you see the custom type there?

1. What happens when you run the example code? Does it work? - It does not work, it does show the AnotherDatePicker class in the custom view type
2. Check the CustomListView example: - Yes I tried that example and it has the class in there
Do you see the custom type there? - YES
 

Wolli013

Well-Known Member
Licensed User
Longtime User
Who is able to me sagem like one gets a picture in the calendar indicated instead of a number.
I left if one birthday har a candle or whatever.
What I must change.

B4X:
' Geburtstagsanzeige
    Dim Bild_Geburtstag As Bitmap
    Bild_Geburtstag.Initialize(File.DirAssets, "geburtstag.png")
  
    If day &"." & month = Geburtstag Then
    cvs.DrawText(day, (((dayOfWeekOffset + day - 1) Mod 7) + 0.5) * boxW, _
    (row + 0.5)* boxH + vCorrection, Typeface.DEFAULT_BOLD, Label1.TextSize, Colors.Black, "CENTER")
    End If
' Geburtstagsanzeige
 

Wolli013

Well-Known Member
Licensed User
Longtime User
So it works
B4X:
Private Sub DrawDays

' Geburtstagsanzeige
If day & "." & month = Geburtstag Then
DrawGeburtstag(cvs, selectedColor, (dayOfWeekOffset + day - 1) Mod 7, (dayOfWeekOffset + day - 1) / 7)
End If
' Geburtstagsanzeige

End Sub

Private Sub DrawGeburtstag(c As Canvas, clr As Int, x As Int, y As Int)

Dim Bitmap1 As Bitmap
Bitmap1.Initialize(File.DirAssets, "geburtstag.png")
Dim r As Rect
r.Initialize(x * boxW, y * boxH, (x + 1) * boxW, (y + 1) * boxH)
cvs.DrawBitmap(Bitmap1, Null, r)

End Sub
 

Pilar-JLSineriz

Active Member
Licensed User
Longtime User
Hi,

I have a problem with anotherdatepicker. When I try to open, I have an error, "the panel should be inicialized", curiolsly, in the previous form, the anotherdatepicker works perfectly.

Thanks for your help
 
Status
Not open for further replies.
Top