Android Question [B4X] B4XPreferencesDialog - time and date validations/restrictions

samikinikar

Member
Licensed User
Longtime User

By using the above library

1. how can I increment/decrement the time by 5 minutes in each click instead of 1 minute ?

B4i_0TX3wrm9sF.png


2. How can I restrict the user not to select old dates ? Only today and coming days to be displayed ?
SS-2019-04-29_12.43.31.png
 

Mahares

Expert
Licensed User
Longtime User
1. how can I increment/decrement the time by 5 minutes in each click instead of 1 minute ?
B4X:
Dim Data As Map = CreateMap("First": "","Last": "", "Date":DateTime.Now, "Time": Null, "Alive": True _
    ,"Sport": "", "Phone":"", "Options":"")
    Dim sf As Object = prefdialog.ShowDialog(Data, "OK", "CANCEL")    
    For i = 0 To prefdialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = prefdialog.PrefItems.Get(i)        
        If pi.ItemType = prefdialog.TYPE_TIME Then
            Dim pm As B4XPlusMinus =prefdialog.CustomListView1.GetPanel(i).GetView(1).Tag
            pm.SetNumericRange(0,55,5)   'increment or decrement by 5
        End If        
    Next    
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
       'other code
    End if


2. How can I restrict the user not to select old dates ? Only today and coming days to be displayed ?
Add the following line in B4Xpage_Created or Activity_Create[
B4X:
prefdialog.SetEventsListener(Me, "Pref")     ' This line needs to be in B4Xpage_Created or Activity_Create
Add the following sub:
B4X:
Sub Pref_IsValid (TempData As Map) As Boolean
    Dim d As Long = TempData.GetDefault("Date", DateTime.Now)
    If d < DateTime.Add(DateTime.now, 0,0, -1)  Then
        prefdialog.ScrollToItemWithError("Date")
        Return False
    End If
    Return True
End Sub
 
Upvote 1
Top