iOS Question Picker (datetime) abnormal :-(

ivanomonti

Expert
Licensed User
Longtime User
abnormal behavior pagination values datapiker ...

B4X:
Sub dataPicker
   
    For i = 0 To sw.Panel.NumberOfViews-1
        If sw.Panel.GetView(i) Is Picker Then
            sw.Panel.RemoveViewAt(i)
        End If
    Next
   
    Dim lis1,lis2,lis3 As List
    lis1.Initialize
    lis2.Initialize
    lis3.Initialize
    ' day
    For i = 1 To 31
        Dim s As String
        If i < 10 Then
            s = "0" & i
        Else
            s = i
        End If
        lis1.Add(s)
    Next
    ' mount
    For i = 1 To 12
        Dim s As String
        If i < 10 Then
            s = "0" & i
        Else
            s = i
        End If
        lis2.Add(s)
    Next
    ' year
    Dim j As Int = DateTime.GetYear(DateTime.Now)-10
    For i = j To j+10
        Dim s As String
        If i < 10 Then
            s = "0" & i
        Else
            s = i
        End If
        lis3.Add(s)
    Next
    '
    Dim mpicker As Picker
    mpicker.Initialize("mpicker")
    mpicker.SetColumnsWidths(Array(80,100,170))
    mpicker.
    mpicker.Color = Colors.White
    mpicker.SetBorder(1,Colors.Black,8)
    mpicker.SetItems(0,lis1)
    mpicker.SetItems(1,lis2)
    mpicker.SetItems(2,lis3)
    sw.Panel.AddView(mpicker,100,100,330,100)
   
End Sub

10845962_812449515485823_4844273504219763308_n.jpg


mmmm
 

stevel05

Expert
Licensed User
Longtime User
If you are looking to create a sequential date picker, it's better to use the DateUtils code Module, and you only need 1 column in the picker.

The Date Utils module will take care of number of days in the month and leap years.


B4X:
Dim Lis1 As List
    Lis1.Initialize
    
    Dim Per As Period
    Per.Initialize
    Per.Years = 0
    Per.Days = 365

    DateTime.DateFormat = "dd MM yyyy"

    Dim StartDate As Long = DateTime.Now
    Dim EndDate As Long = DateUtils.AddPeriod(StartDate,Per)
    Dim Date As Long = StartDate
    Log(DateTime.Date(StartDate))
    Log(DateTime.Date(EndDate))

    Per.Initialize
    Per.Days = 1

    Do While Date < EndDate
    
        Lis1.Add(DateTime.Date(Date))
    
        Date = DateUtils.AddPeriod(Date,Per)
    Loop

    Picker1.SetItems(0,Lis1)
 
Last edited:
Upvote 0
Top