toggle panel on MENU keypress

gapi

Active Member
Licensed User
Longtime User
Hi all, I want show/hide a panel created from designer on MENU click event.

Here the code:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_MENU Then
      Activity.LoadLayout("layoutShowOneCliente")
                Panel1.visible = True
      Return True
    End If
    Return False
End Sub

how can in some Sub hide that panel1 ? tnx
 

gapi

Active Member
Licensed User
Longtime User
Keycode_menu

many tnx NJDude for you sample, perfect, a question:

Can I make a conditional in key_press sub ?

B4X:
If KeyCode = KeyCodes.KEYCODE_MENU Then
        Activity.LoadLayout("layoutShowOneCliente")
If Panel1.visible = false
 Panel1.visible = True
Then
 Panel1.visible = False
End If
        Return True
    End If
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Your code should be
B4X:
If KeyCode = KeyCodes.KEYCODE_MENU Then
    Activity.LoadLayout("layoutShowOneCliente")
    If Panel1.visible = false Then
        Panel1.visible = True
    Else
        Panel1.visible = False
    End If        
    Return True
End If
Although this is neater
B4X:
If KeyCode = KeyCodes.KEYCODE_MENU Then
    Activity.LoadLayout("layoutShowOneCliente")
    Panel1.visible = Not (Panel1.visible)   
    Return True
End If
 
Upvote 0
Top