Android Question Extend the activity_keypress event to a class

DavideV

Active Member
Licensed User
Longtime User
Hi developers,
i made a class that adds menu to any activity. Actually to close the menu i call a sub in the class from the activity_keypress event of the activity:

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    'key interception, here if back or menu key pressed
           
    If KeyCode = KeyCodes.KEYCODE_BACK Then   
       
        'close menu if opened
        If Menu.IsVisible Then
            Menu.CloseMenu
            Return True
        End If

    End If  
    Return False
   
End Sub

Is there a way to extend the keypress event to the class itself so it doesn't rely on the activity?

Thanks in advance.
Davide
 
Top