Android Question DateTemplate: How to disable some weekdays

toby

Well-Known Member
Licensed User
Longtime User
I want to force users to select either a Sunday or a Monday, and I'm wondering whether there is an easy way to disable other 5 columns: Tuesday, Wednesday, Thursday, Friday and Saturday.

TIA
 

Mahares

Expert
Licensed User
Longtime User
n easy way to disable other 5 columns: Tuesday, Wednesday, Thursday, Friday and Saturday.
I am not sure there is an easy way to disable the entire columns, someone may be able to offer you that, But, give this a try Toby. You are not shy, you will let us know if it is not suitable for you.
B4X:
Private DateTemplate As B4XDateTemplate

Sub Button1_Click
    Wait For (GetDateSundayOrMonday) Complete (Ticks As Long)
    If Ticks > 0 Then
        Log($"Selected date: $Date{Ticks}"$)
    End If
End Sub

Private Sub GetDateSundayOrMonday As ResumableSub
    Do While True
        Wait For (dialog.ShowTemplate(DateTemplate, "", "", "Cancel")) Complete (Result As Int)
        Dim zero As Long = 0
        If Result = xui.DialogResponse_Cancel Then Return zero
        If   DateTime.GetDayOfWeek(DateTemplate.Date)  > 2  Then  'sun and mond allowed
            Wait For (dialog.Show("Invalid date", "Ok", "", "")) Complete (Result As Int)
        Else
            Return DateTemplate.Date
        End If
    Loop
    Return 0
End Sub
 
Upvote 2

TILogistic

Expert
Licensed User
Longtime User
see:

or modify it to your needs

 
Upvote 2

toby

Well-Known Member
Licensed User
Longtime User
both of above solutions work for me. Thanks.

Now I understand that it's not trivial to disable the dates I don't want until modifying the library source code.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
both of above solutions work for me
The code I posted for you disables every day of the week except Sunday and Monday of any date.. I tested it and it works. But, can you show how you modified the code in post #3 link to make it work for you, because its code allows you to only select a given date between two dates, not necessarily Sunday or Monday. I am curious. Thanks
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
The code I posted for you disables every day of the week except Sunday and Monday of any date
Your solution is much better since I don't have to make any change; I've focused too much on the validation approach to pay attention to other details. Both solutions use validation after user selection instead of disabling unwanted dates, which is how I plan to implement in my app.

Thank you very much for your helps!
 
Upvote 0
Top