Android Question Is there a way to capture the back key click event in a custom view?

demasi

Active Member
Licensed User
Longtime User
Hello all,

Is there a way to capture the back key click event in a custom view?

And if this is possible, is also possible to send the key back to the main activity for normal processing?

Thank you!
 

LucaMs

Expert
Licensed User
Longtime User
I think that any type is the view that currently has the focus, the Back Key is intercepted by the Activity.

You can do the opposite; you can add a property to your custom view so as to pass a value from the Activity to your view, indicating that Back Key was pressed.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not directly. You will need to call the relevant sub from Activity_KeyPress (in the main module).

You can return a boolean variable and if it is true then return from Activity_KeyPress:
B4X:
Sub Activity_KeyPress (KeyCode As Int) 
   If MyCustomView.KeyPress(KeyCode) = True Then Return True
   Return False
End Sub
 
Upvote 0
Top