Android Code Snippet Activity_Click and Activity_KeyPress in B4XPages

I figured out a way to tweak Activity_Click and Activity_KeyPress in B4XPages.
The first thing you will do is make in the B4XPage the controls you want to use public. Then in Main Activity you just add this. The code is created for Activity_Click but it can be easily manipulated to handle the keycodes in each page if this code is placed in Activity_KeyPress and change the handling code in each case.

Sub Activity_Click
    Dim b4xpinfo As B4XPageInfo
    b4xpinfo = B4XPages.GetManager.GetTopPage
    Select Case b4xpinfo.Id
        Case "mainpage"
            If B4XPages.MainPage.pnlLegal.Visible = True Then
                B4XPages.MainPage.cmdLegal.Visible = True
                B4XPages.MainPage.pnlLegal.Visible = False
            End If
    End Select
End Sub
Last edited:


Well-Known Member
Licensed User
Longtime User
Ha ha ha ha... There is always a simpler way: