M Ms Boar New Member Licensed User Oct 16, 2018 #1 Hello everyone, I have a tiny doubt about the correct sintax with MenuItem. Im tryin to simplify my life a bit, with the menus, but today its not my lucky day. So these are my methods Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Login") InputLogin1.Hint = "Name" Activity.Title ="Login" AuxCode.Menu_Charge(Activity,Null) ''My aux methods End Sub ''my menu constructor, in an Auxiliar module called auxCode Code: Copy Sub Menu_Charge(Act As Activity, status As String) Act.AddMenuItem("About", about_Click) (...) EndSub 'The click Method Sub about_Click Msgbox("Version X", "MyAPP") End Sub The behaviuour with this code block is that when activity starts the msgbox is shown ( so if its called 7 times, the msgbox its shown 7 times) So, Surfing through the forum, I´ve see that the ''best way or correct'' syntax is with callsubdelayed, but when I write : Code: Copy Act.AddMenuItem("About", CallSubDelayed(something, "about_Click")) 1st Something needs to be a component, but i do not understand which component should be there. Anything i write, :: B4A tells that I cant assing this to an empty value. My question is, if is not a syntax error ( that i beg it is... ) , it is possible to create the menus by this way, or it is preffered to use a button and a spinner by my own way. Kind Regards, MsB
Hello everyone, I have a tiny doubt about the correct sintax with MenuItem. Im tryin to simplify my life a bit, with the menus, but today its not my lucky day. So these are my methods Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Login") InputLogin1.Hint = "Name" Activity.Title ="Login" AuxCode.Menu_Charge(Activity,Null) ''My aux methods End Sub ''my menu constructor, in an Auxiliar module called auxCode Code: Copy Sub Menu_Charge(Act As Activity, status As String) Act.AddMenuItem("About", about_Click) (...) EndSub 'The click Method Sub about_Click Msgbox("Version X", "MyAPP") End Sub The behaviuour with this code block is that when activity starts the msgbox is shown ( so if its called 7 times, the msgbox its shown 7 times) So, Surfing through the forum, I´ve see that the ''best way or correct'' syntax is with callsubdelayed, but when I write : Code: Copy Act.AddMenuItem("About", CallSubDelayed(something, "about_Click")) 1st Something needs to be a component, but i do not understand which component should be there. Anything i write, :: B4A tells that I cant assing this to an empty value. My question is, if is not a syntax error ( that i beg it is... ) , it is possible to create the menus by this way, or it is preffered to use a button and a spinner by my own way. Kind Regards, MsB
Erel B4X founder Staff member Licensed User Longtime User Oct 17, 2018 #2 Never use Msgbox. Only MsgboxAsync. Ms Boar said: So, Surfing through the forum, I´ve see that the ''best way or correct'' syntax is with callsubdelayed, but when I write : Click to expand... I don't understand what you are trying to solve. The code itself is incorrect. Upvote 0
Never use Msgbox. Only MsgboxAsync. Ms Boar said: So, Surfing through the forum, I´ve see that the ''best way or correct'' syntax is with callsubdelayed, but when I write : Click to expand... I don't understand what you are trying to solve. The code itself is incorrect.
M Ms Boar New Member Licensed User Oct 17, 2018 #3 Hi, Maybe Code its not complete Even using Code: Copy MsgboxAsync("Version X", "MyAPP") Message appears when activities start. At the start of each activity, where my sub menu_charge is called, the msgboxasync is shown , then in the menu, at click in the row do nothing, the msgbox does not appear. What im trying to solve : Shown distincts menus depending on the user. My problem is that the msgboxAsycn is shown when activity starts and do not respond when clicked. Surfing forum i ve found the most similar... but do not solve my trouble https://www.b4x.com/android/forum/threads/addmenuitem-and-android-7.71542/ Where.. This is not a bug. You shouldn't show modal dialogs in the menu click event (see the documentation). Use CallSubDelayed to call a method from the menu event and show the msgbox there. Click to expand... Acording to this, if I should use callsub delayed, when I try shows an error "cant assing to empty value" So i have the doubt that if it is need to use callsubdelayed, which component as object should be? Code: Copy 'callsubdeladey(object, sub, arguments) Act.AddMenuItem("TITLE",CallSubDelayed2("Which Object should be here?", "about_click",Null ( no arguments)) Which Is the best way/correct way/ correct sintax to use application menu to interact with? Thank you! Upvote 0
Hi, Maybe Code its not complete Even using Code: Copy MsgboxAsync("Version X", "MyAPP") Message appears when activities start. At the start of each activity, where my sub menu_charge is called, the msgboxasync is shown , then in the menu, at click in the row do nothing, the msgbox does not appear. What im trying to solve : Shown distincts menus depending on the user. My problem is that the msgboxAsycn is shown when activity starts and do not respond when clicked. Surfing forum i ve found the most similar... but do not solve my trouble https://www.b4x.com/android/forum/threads/addmenuitem-and-android-7.71542/ Where.. This is not a bug. You shouldn't show modal dialogs in the menu click event (see the documentation). Use CallSubDelayed to call a method from the menu event and show the msgbox there. Click to expand... Acording to this, if I should use callsub delayed, when I try shows an error "cant assing to empty value" So i have the doubt that if it is need to use callsubdelayed, which component as object should be? Code: Copy 'callsubdeladey(object, sub, arguments) Act.AddMenuItem("TITLE",CallSubDelayed2("Which Object should be here?", "about_click",Null ( no arguments)) Which Is the best way/correct way/ correct sintax to use application menu to interact with? Thank you!
OliverA Expert Licensed User Longtime User Oct 17, 2018 #4 Ms Boar said: This is not a bug. You shouldn't show modal dialogs in the menu click event (see the documentation). Use CallSubDelayed to call a method from the menu event and show the msgbox there. Click to expand... The way I interpret this is that you should have Code: Copy Act.AddMenuItem("About", about_Click) and then do Code: Copy Sub about_Click CallSubDelayed(Me, "about_showsomething") End Sub Sub about_showsomething 'do what you need to be done End Sub Notice I use Me in the CallSubDelayed, since the sub in this example is in the same class module code module. If the sub is in a different code module/Activity/Service, then use that code module's/Activity's/Service's name (Main for example). See: https://www.b4x.com/android/forum/t...teract-between-activities-and-services.18691/ Upvote 0
Ms Boar said: This is not a bug. You shouldn't show modal dialogs in the menu click event (see the documentation). Use CallSubDelayed to call a method from the menu event and show the msgbox there. Click to expand... The way I interpret this is that you should have Code: Copy Act.AddMenuItem("About", about_Click) and then do Code: Copy Sub about_Click CallSubDelayed(Me, "about_showsomething") End Sub Sub about_showsomething 'do what you need to be done End Sub Notice I use Me in the CallSubDelayed, since the sub in this example is in the same class module code module. If the sub is in a different code module/Activity/Service, then use that code module's/Activity's/Service's name (Main for example). See: https://www.b4x.com/android/forum/t...teract-between-activities-and-services.18691/
M Ms Boar New Member Licensed User Oct 17, 2018 #5 Thanks for your answer, the key is that about_Click is on a module, so do not support Me keyword, What im feeling is that it is need to code in an explicit form each menu at each activity, and it is not posible to set a general menu in a code module, that creates each menu depending on the activity. I will keep on trying, its just a felling, cannot be true. Thank you all! Upvote 0
Thanks for your answer, the key is that about_Click is on a module, so do not support Me keyword, What im feeling is that it is need to code in an explicit form each menu at each activity, and it is not posible to set a general menu in a code module, that creates each menu depending on the activity. I will keep on trying, its just a felling, cannot be true. Thank you all!
OliverA Expert Licensed User Longtime User Oct 17, 2018 #6 Ms Boar said: module, so do not support Me keyword Click to expand... Huh? Do a log(Me) on a code module. It should work (warning: not an expert. Time to experiment). Upvote 0
Ms Boar said: module, so do not support Me keyword Click to expand... Huh? Do a log(Me) on a code module. It should work (warning: not an expert. Time to experiment).
M Ms Boar New Member Licensed User Oct 17, 2018 #7 Almost mine, error red: "Code modules do not support Me Keyword" Upvote 0
OliverA Expert Licensed User Longtime User Oct 17, 2018 #8 Ugh. Like I said, not an expert (it works in B4J, so odd that it does not work in B4A). Put the called sub in another module and try Code: Copy CallSubDelayed(TheOtherCodeModule, "about_showsomething") Note: Ignore. This does not work in B4A (does in B4J, not B4A) Last edited: Oct 17, 2018 Upvote 0
Ugh. Like I said, not an expert (it works in B4J, so odd that it does not work in B4A). Put the called sub in another module and try Code: Copy CallSubDelayed(TheOtherCodeModule, "about_showsomething") Note: Ignore. This does not work in B4A (does in B4J, not B4A)
DonManfred Expert Licensed User Longtime User Oct 17, 2018 #9 I dont think it will help here at all. Using callsubdelayed the sub is called after activity_create finishes. You only can add menuitems in activity create. Exception when you are using AppCompat. Upvote 0
I dont think it will help here at all. Using callsubdelayed the sub is called after activity_create finishes. You only can add menuitems in activity create. Exception when you are using AppCompat.