Android Question ActionBar e menù

magi6162

Well-Known Member
Licensed User
My code:
B4X:
Sub Gobal
    Dim SAB As StdActionBar
    Dim dummy As Panel
end sub

Sub Activity_Create(FirstTime As Boolean)
    
.............
   Activity.AddMenuItem3("Report","AB_Report",LoadBitmap(File.DirAssets, "report.png"),True)
    Activity.AddMenuItem3("Statistiche","AB_Statistiche",LoadBitmap(File.DirAssets, "statistiche.png"),True)
'    Activity.AddMenuItem3("Opzioni","AB_Opzioni",LoadBitmap(File.DirAssets, "opzioni.png"),True)
    Activity.AddMenuItem3("Mese precedente","AB_MeseP",LoadBitmap(File.DirAssets, "precedente.png"),True)
    Activity.AddMenuItem3("Mese successivo","AB_MeseS",LoadBitmap(File.DirAssets, "successivo.png"),True)
    Activity.AddMenuItem3("PopUp","AB_PopUp",LoadBitmap(File.DirAssets, "ic_action_menu.png"),True)
   
    SAB.Initialize("SAB")
    SAB.Icon = LoadBitmap(File.DirAssets, "a_execute_256.png")
    SAB.Subtitle = versione
    SAB.NavigationMode = SAB.NAVIGATION_MODE_STANDARD
    SAB.ShowUpIndicator = True

................
End Sub

Sub AB_PopUp_Click
    dummy.Initialize("")
    Activity.AddView(dummy, 80%x, 0, 1dip, 1dip)
    dummy.Color = Colors.Transparent
    flgMenu = Not (flgMenu)
   
    'Create and show popup menu
    Dim pop As PopupMenu
    pop.Initialize("ABPop", dummy)
    pop.AddMenuItem(1, "Estensione calendario", TalkCode.GetDrawable("ic_calendar"))
    pop.AddMenuItem(2, "Databases", TalkCode.GetDrawable("ic_databases"))
    pop.AddMenuItem(3, "Lingue", TalkCode.GetDrawable("ic_lingue"))
    pop.AddMenuItem(4, "Opzioni", TalkCode.GetDrawable("ic_opzioni"))
    pop.AddMenuItem(5, "Info", TalkCode.GetDrawable("ic_info"))
   
    pop.Show
End Sub

' Remove the dummy view from the activity
Sub ABPop_Closed
    dummy.RemoveView
End Sub

Sub ABPop_ItemClicked (Item As MenuItem)
    Select Case Item.Id
        Case MENU_ITEM_AMPLIA_CALENDARIO
            mnuAmpliaCal_Click
        Case MENU_ITEM_DATABASES
            mnuDatabases_Click
        Case MENU_ITEM_LINGUE
            mnuLingue_Click
        Case MENU_ITEM_OPZIONI
            mnuOpzioni_Click
        Case MENU_ITEM_INFO
            mnuInfo_Click
    End Select
End Sub
I would use the menu key to make you appear popoup menu and to hide it.
How can I do? Thank you all.
 

magi6162

Well-Known Member
Licensed User
i try:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        btnEsci_Click
    End If
    If KeyCode = KeyCodes.KEYCODE_MENU Then
        If flgMenu = False Then
            AB_PopUp_Click
        Else
            ABPop_Closed
        End If
    End If
    Return True
End Sub
but it works only once. then no longer appears.
 

magi6162

Well-Known Member
Licensed User
I try:
B4X:
Sub AB_PopUp_Click As Boolean
    dummy.Initialize("")
    Activity.AddView(dummy, 80%x, 0, 1dip, 1dip)
    dummy.Color = Colors.Transparent
    flgMenu = Not (flgMenu)
   
    'Create and show popup menu
    Dim pop As PopupMenu
    pop.Initialize("ABPop", dummy)
    pop.AddMenuItem(1, "Estensione calendario", TalkCode.GetDrawable("ic_calendar"))
    pop.AddMenuItem(2, "Databases", TalkCode.GetDrawable("ic_databases"))
    pop.AddMenuItem(3, "Lingue", TalkCode.GetDrawable("ic_lingue"))
    pop.AddMenuItem(4, "Opzioni", TalkCode.GetDrawable("ic_opzioni"))
    pop.AddMenuItem(5, "Info", TalkCode.GetDrawable("ic_info"))
   
    pop.Show
    Return True
End Sub

' Remove the dummy view from the activity
Sub ABPop_Closed As Boolean
    dummy.RemoveView
    Return True
End Sub
Sub Activity_KeyPress(KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        btnEsci_Click
    End If
    If KeyCode = KeyCodes.KEYCODE_MENU Then
        If flgMenu = False Then
'Try to use CallSubDelayed to call these two methods and return True from this sub.           
            CallSubDelayed(Me,"AB_PopUp_Click")
        Else
            CallSubDelayed(Me,"ABPop_Closed")
        End If
    End If
    Return True
End Sub
but not work.
Thanks for help
 

magi6162

Well-Known Member
Licensed User
Log:
LogCat connected to: 192.168.56.101:5555
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
KeyPress
KeyPress: flgmenu = False
PopupClick: flgmenu = true
Set Icon
Set Icons visible
Done
Set Icon
PopupShow: flgmenu = true
PopupClosed: flgmenu = false
thanks
 

Attachments

magi6162

Well-Known Member
Licensed User
LogCat connected to: 192.168.56.101:5555
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
KeyPress
KeyPress: flgmenu = False
PopupClick: flgmenu = true
Set Icon
Set Icons visible
Done
Set Icon
PopupShow: flgmenu = true
PopupClosed: flgmenu = false First

KeyPress
KeyPress: flgmenu = False
PopupClick: flgmenu = true
Set Icon
Set Icons visible
Done
Set Icon
PopupShow: flgmenu = true
PopupClosed: flgmenu = false Second

KeyPress
KeyPress: flgmenu = False
PopupClick: flgmenu = true
Set Icon
Set Icons visible
Done
Set Icon
PopupShow: flgmenu = true
PopupClosed: flgmenu = false third

...ecc
Best regards
 
Top