Android Question closing a view

67biscuits

Member
pulling my hair out over a calendar:
Sub createGrid(Col As Int, Row As Int)
    Dim now As Long = DateTime.Now
'    Public DPpnl As Panel
    Dim gap As Int = 2dip
    Dim wday As Label
    Public spn As Spinner
    Dim close As Button
   
    DPpnl.Initialize("DPpnl")
    wday.Initialize("wday")
    close.initialize("close")

    DPpnl.Color = xui.Color_white
    DPpnl.Elevation = 20dip
    Activity.AddView(DPpnl,40dip, 0dip, 280dip - gap, 380dip - gap)
    Dim spnWidth As Int = DPpnl.Width / 2 - gap
    Dim btnWH As Int = DPpnl.Width/Col
    Public btns As List
    btns.Initialize

    '========add the views ==============
    'create and set Month selector spinner  ==================
    spn.initialize("spnM")
    DPpnl.AddView(spn, 0dip, 0dip, spnWidth, 40dip)
    spn.Addall(mths)
    spn.SelectedIndex = (activeMonth-1)
   
    'create and set year selector spinner  =============
    spn.initialize("spnY")
    DPpnl.AddView(spn, spnWidth- gap , 0dip, spnWidth - gap , 40dip)
    spn.Addall(Array As Int( DateTime.GetYear(now)- 1, DateTime.GetYear(now)))
    spn.selectedindex = (DateTime.GetYear(now))
   
    'create and set the 42 possible month days buttons
    Dim d As Int = 0
    Dim top As Int = 40dip
    For r = 1 To Row
        top = top + 40dip
        For c = 0 To Col - 1
            d = d + 1
            Dim btn As Button
            btn.Initialize("btn")
            DPpnl.AddView(btn, c*40dip, top + gap, btnWH, btnWH)
            btn.TextSize = 10
            btns.Add(btn)
            btn.Text = ""
        Next
    Next
    DPpnl.AddView(close, spnWidth, top + 40dip, spnWidth,40dip)
    close.Text = "Close"
   
    'create string of month and force a double digit
    Dim aMonth As String = activeMonth
    If aMonth.Length = 1 Then aMonth = $"0${aMonth}"$
   
    'no bleedin' clue, mate!!
    Dim olddate As String = DateTime.DateFormat
    DateTime.DateFormat = "MM/dd/yyyy"
    TT = myParseDate($"${aMonth}/01/${activeYear}"$)

    Dim day1 As Int = DateTime.GetDayOfWeek(TT)-1
    Dim last1 As Int = DateUtils.numberofdaysinmonth(activeMonth,activeYear)

    DateTime.dateformat = olddate

    '=======fill the spots ===============
    For x = 0 To 6
        Dim wday As Label
        wday.Initialize("wday")
        DPpnl.AddView(wday, x * btnWH + gap, 40dip + gap, btnWH, btnWH)
        wday.Text = $" ${days.get(x)}"$
    Next
   
    'add in day of month numbers
    For x = 0 To last1-1
        btns.Get(x+day1).As (Button).text = x+1
    Next
Log($"Actual month: ${DateTime.GetMonth(now)}, activeMonth: ${activeMonth}"$)

    If DateTime.GetMonth(now) = activeMonth Then
        btns.Get(day1).As(Button).Color = xui.Color_Red
    End If

End Sub

Sub close_Click
    Log("Closed")
    DPpnl.RemoveView
    DPpnl.visible = False
    DPpnl.RemoveAllViews
End Sub

Above are two subs. One to put the calendar on the screen, and one to (in theory) remove it.
The purpose is simply to select a date if required other than 'today', to mark edited data entries for later analysis.

The sub to open the calendar works well. When I hit the 'Close' button, the panel closes, disappears off the screen, as it should.
If I select an alternate month, the calendar will display the calendar properly, in order, starting on the correct day.

This is where the issue starts. When I press the 'Close' button, if I have changed the month, the calendar will renumber to display May (or current month), and NOT close. The spinner displaying the selected month remains on the users selection, (Apr, in this case).

In the sub close_Click, I have tried all the methods I know of to remove the view, and as aforementioned, will work as long as I do not change the month.
The log to show 'Closed' just shows that that sub is running despite any action executed prior.

Any insight would be appreciated.
Thanks

Charley

p.s.
days and mnths are the weekday names and month names, respectively, declared elsewhere in the program

(Edited addition, when you hit a calendar date)

what happens when you hit a calendar date:
Sub btn_Click
    Dim now As Long = DateTime.Now
    Dim b As Button = Sender
    If b.Text <> "" Then
        Dim am As String = $"${IIf(activeMonth < 10,"0","")}${activeMonth}"$
        Dim ad As String = $"${IIf(b.Text < 10,"0","")}${b.text}"$
        Dim tickDate As Long = myParseDate($"${am}/${ad}/${activeYear}"$)
Log($"actual month: ${DateTime.GetMonth(DateTime.Now)}, am: ${am}, ad: ${ad}, b: ${b.text}"$)

        If tickDate < now Then
            TT = tickDate
        Else
            MsgboxAsync("You cannot work in the future", "Whoops!")
            TT = now
        End If
    
    End If
    cmdDatePicker.Text = DateTime.Date(TT)
    
End Sub
 

67biscuits

Member
I figured it out. I was creating a grid on a grid after selecting the month from a spinner. I have outsourced the filling in of the month days to a separate sub which is called by the spinners and the cmdDatePicker button.

Thanks anyway. ; )
 
Upvote 0
Top