Android Question AnotherDatePicker gray out past days

apty

Active Member
Licensed User
Longtime User
I am using anotherdatepicker to select dates for my app. I would like to gray out/disable past dates (i.e days from yesterday backwards) so that they are not selected. Please help on how to achieve this.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Code to draw disabled days:

SS-2018-06-24_09.45.44.png


DrawDays sub:
B4X:
Dim ValidDate As Long = DateUtils.SetDate(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now))
   For day = 1 To daysInMonth
       Dim clr As Int = xui.Color_Black
       If DateUtils.SetDate(year, month, day) < ValidDate Then
           clr = xui.Color_Gray
       End If
       Dim row As Int = (day - 1 + dayOfWeekOffset) / 7
       cvs.DrawText(day, (((dayOfWeekOffset + day - 1) Mod 7) + 0.5) * boxW, _
           (row + 0.5)* boxH + vCorrection, daysFont, clr, "CENTER")
   Next

You will also need to change HandleMouse to prevent from selecting invalid days. The code should be similar.
 
Upvote 0
Top