Android Question ActionBar e menù

Discussion in 'Android Questions' started by magi6162, Jun 7, 2015.

  1. magi6162

    magi6162 Active Member Licensed User

    My code:
    Code:
    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%x01dip1dip)
        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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can handle the menu key with Activity_KeyPress.
     
  3. magi6162

    magi6162 Active Member Licensed User

    i try:
    Code:
    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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Try to use CallSubDelayed to call these two methods and return True from this sub.
     
  5. magi6162

    magi6162 Active Member Licensed User

    I try:
    Code:
    Sub AB_PopUp_Click As Boolean
        dummy.Initialize(
    "")
        
    Activity.AddView(dummy, 80%x01dip1dip)
        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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Maybe it is not related to the menu button at all. Does it work properly if you show the popup multiple times by clicking on a standard button?
     
  7. magi6162

    magi6162 Active Member Licensed User

    yes

    thanks for help
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Please try to create a simple project that demonstrates this issue and upload it.
     
  9. magi6162

    magi6162 Active Member Licensed User

    test app

    thanks for all
     

    Attached Files:

  10. Erel

    Erel Administrator Staff Member Licensed User

    What are the steps to reproduce it? I'm able to open the popup menu multiple times.
     
  11. magi6162

    magi6162 Active Member Licensed User

    use key menu hardware

    thanks
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    The device I currently test with don't have a hardware button. Use the debugger or add some log messages to see what happens. Check whether Activity_KeyPress is raised.
     
  13. magi6162

    magi6162 Active Member Licensed User

    thanks
     

    Attached Files:

  14. Erel

    Erel Administrator Staff Member Licensed User

    What happens when click on the menu button another time?
     
  15. magi6162

    magi6162 Active Member Licensed User

    Best regards
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    So the problem is not related to the menu button. It is handled properly.
     
  17. magi6162

    magi6162 Active Member Licensed User

    how do I fix ?

    thank you all
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but I'm not familiar with the implementation of this library. It seems like the problem is there. You can try to use the same menu instead of creating it and removing it each time.
     
  19. magi6162

    magi6162 Active Member Licensed User

    the menu changes depending on the context.

    I do not know how to do.

    thanks for help
     
Loading...