5. access the dialog
Lets clean up our working environment. Close all the IDE's except the budget_tutorial project.
Add the newly compiled library to the project. Remember the library files are saved in the AdditionalLibraries folder!
In the SettingsPage you can declare the variables needed:
' calendar dialog
Private cal As calendar
Private pnl1 As Panel
Private currentticks As Long = DateTime.Now
Public currentmonth As Int = DateTime.GetMonth(currentticks)
Public currentyear As Int = DateTime.GetYear(currentticks)
Public currentday As Int = DateTime.GetDayOfMonth(currentticks)
Public lblseldate As Label
Private caldialog As B4XDialog
Private btnnext As Button
Private btnprev As Button
Public displayyear As Int
Public displaymonth As Int
Public setdate As String
And to initialize:
' calendar dialog
cal.Initialize(Me,"cal")
caldialog.Initialize(Root)
caldialog.PutAtTop = True
caldialog.BackgroundColor = Colors.White
lblseldate.Initialize("")
pnl1.Initialize("")
displayyear = currentyear
displaymonth = currentmonth
To use the library you can write some dialog code.
Make in the SettingsPage tab a subroutine called datepicker_dialog.
Initialize a panel to use in the custom dialog and set the text from the label lblseldate to empty.
lblseldate.Text = ""
pnl1.Color = Colors.White
pnl1.SetLayoutAnimated(0dip, 0dip, 0dip, 278dip, 368dip)
Then use the calendar object and its method set_date_picker to fill the panel.
The panel contains a label and 2 buttons above a month panel.
pnl1 = cal.set_date_picker(displaymonth,displayyear)
Dim rsub1 As ResumableSub = caldialog.ShowCustom(pnl1, "OK", "", "CANCEL")
Wait For (rsub1) Complete (Result As Int)
Now it's time to process the result of the dialog.
If the user presses the OK button from the dialog then we check the Result variable for a positive response.
The setdate variable is used to determine which date icon button was pressed in the settings layout.
If Result = xui.dialogResponse_Positive Then
If setdate = "startdate" Then
ftfstart.Text = lblseldate.Text
B4XPages.MainPage.strstartticks = cal.lblticks
End If
If setdate = "enddate" Then
ftfend.Text = lblseldate.Text
B4XPages.MainPage.strendticks = cal.lblticks
End If
End If
If the response is negative then the label will be set to empty.
The displayyear and displaymonth variables are used to load the previous or next month (see the code below).
If Result = xui.dialogResponse_Negative Then
lblseldate.Text = ""
End If
displayyear = currentyear
displaymonth = currentmonth
To call the set_date_picker dialog in the btnstart_Click event use this code:
Sub btnstart_Click
setdate = "startdate"
datepicker_dialog
End Sub
To call the set_date_picker dialog in the btnend_Click event use this code:
Sub btnend_Click
setdate = "enddate"
datepicker_dialog
End Sub
The click (or tap) events from the calendar dialog are handled in the callback subroutines.