Android Question AS_DatePicker select the current day by code

toro1950

Active Member
Licensed User
Hi, I'm using Alexander Stolte's AS_DatePicker library with great satisfaction. When the app starts, it displays the current month and day. I'd like to have the app automatically select the day. Is this possible, and if so, how?
Thanks in advance
 

oliverhaven13

New Member
Yes, it’s possible. When the DatePicker is created, you can just set its selected_date (or set_selected_date, depending on the version). If you pass date.today() right after initializing the widget, it will highlight the current day automatically. I’m using it this way and it works fine.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
B4X:
Dim sel_date As Long = DateTime.Add(DateTime.Now, 0, 0, -2) '2 days ago or which date that you want
AS_DatePicker1.SelectedDate = sel_date
1764160552271.png
 
Upvote 0

toro1950

Active Member
Licensed User
Thank you asales, the day is displayed but not selected, I need to simulate the choice made with the manual tap,
practically simulate the sub Private Sub AS_DatePicker1_SelectedDateChanged(Date As Long)
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Thank you asales, the day is displayed but not selected, I need to simulate the choice made with the manual tap
In my libraries, if there is something to note about a property or function, I always write a description.
After you have set SelectedDate, you must call .Refresh.
1764176975725.png


Just like @asales did, but with the following addition:
B4X:
Dim sel_date As Long = DateTime.Add(DateTime.Now, 0, 0, -2) '2 days ago or which date that you want
AS_DatePicker1.SelectedDate = sel_date
AS_DatePicker1.Refresh
 
Upvote 0

toro1950

Active Member
Licensed User
This doesn't solve my problem; it doesn't simulate clicking (tapping) on the day. I solved it this way:
I created a sub called selection, and inside it I put the code from the sub AS_DatePicker1_SelectedDateChanged(Date As Long). When called by a click, it calls the selection sub. Then I put the code you gave me at the end of the AS_DatePicker1_CustomDrawHeader sub, calling the selection sub.
maybe a little cumbersome but it works, anyway thank you all
 
Upvote 0
Top