iOS Question How do I dynamically create a date picker?

davepamn

Active Member
Licensed User
I need to dynamically create a date picker for a scrollview and then initialize it with a parameter date.
 

Erel

Administrator
Staff member
Licensed User
B4X:
Dim dp As DatePicker
dp.Initialize("dp")
dp.Ticks = DateTime.Now
Page1.RootPanel.AddView(dp,0, 0, 100%x, 200)
 

davepamn

Active Member
Licensed User
How do I set the date picker using mm/dd/yyyy?

Do you have a function that converts a date into ticks
 

davepamn

Active Member
Licensed User
B4X:
    Dim arrDatePicker(100) As DatePicker

    arrDatePicker(iDatePickerCounter).Mode=arrDatePicker(iDatePickerCounter).MODE_DATE
    DateTime.DateFormat = "MM/dd/yyyy"
    arrDatePicker(iDatePickerCounter).Ticks=DateTime.DateParse(sTestIdValue)
This code worked! I was able to set a date and format to Month, Day, and Year in the Picker Control
 

davepamn

Active Member
Licensed User
this snippet reverses the ticks to a date
B4X:
sTestValue=GetDate(arrDatePicker(i).ticks)

Public Sub GetDate(Ticks As Long) As String

    Dim df As String = DateTime.DateFormat

    DateTime.DateFormat = "MM/dd/yyyy"

    Dim res As String = DateTime.Date(Ticks)

    DateTime.DateFormat = df

    Return res

End Sub
 

Erel

Administrator
Staff member
Licensed User
The picker cannot be dismissed. You can remove it like you remove any view (dp.RemoveFromParent).
 

gjoisa

Active Member
Licensed User
In other applications there will be done button to dismiss the picker in Iphone . In Ipad if we touch the out side area of picker it will be dismissed . How the do that ?
 

Erel

Administrator
Staff member
Licensed User
You can handle the Page_Click event and call Page.ResignFocus.
 
Top