Create secondary form when I press a jButton lazarus / 43-Android ---------------------------------------------------------------------- Bandy · 2025-07-22 09:50 Hello. In LAMW4Windows v3.8, I want to create a secondary form when I press a jButton placed on the primary form and return to the primary form when I press the "come back" button (<). Please help... ---------------------------------------------------------------------- dseligo · 2025-07-22 10:12 If i.e. your second form is fmForm2, something like this should work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if fmForm2 = nil thenbegin  gApp.CreateForm(TfmForm2, fmForm2);  fmForm2.Init;end; fmForm2.Show; ---------------------------------------------------------------------- Bandy · 2025-07-22 12:02 I think I made a confusion in my first post. I have AndroidModule1 (primary form) with one Button1:jButton, statically created, by hand. When I press Button1 I want to show secondary form (maybe called AndroidModule2), that is statically created (not dynamically created by code), and contains one EditText1:jEditText and one ListView1:jListView. When secondary form it's shown, I want to press the "come back" button (<) on the screen and secondary form to be closed and primary form to come back on the display. I hope it's clear now. ---------------------------------------------------------------------- nicelybrewed · 2025-07-22 20:32 This may help: https://forum.lazarus.freepascal.org/index.php/topic,69165.0.html Then use KEYCODE_BACK to catch your back key tap to close AndroidModule2 using the OnSpecialKeyDown event on the AndroidModule2 form: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule2.AndroidModule2SpecialKeyDown(Sender: TObject; keyChar: char;  keyCode: integer; keyCodeString: string; var mute: boolean);beginif (KeycodeString = 'KEYCODE_BACK') then  begin       AndroidModule2.close;    mute := true;   end; end; Remember your Form will be transparent by default and you will need to set a BackgroundColor or you won't see it. ---------------------------------------------------------------------- Bandy · 2025-07-23 08:17 I've read the link you sad it may help me, but the AndroidModule2 is created dynamically (by using code gApp.CreateForm). I don't want like this. I want to show secondary form AndroidModule2 like I was doing in Lazarus IDE 4.0 for Windows: from File Menu -> New Form (this means statically), then I will add Buttons, ListViews, etc. to the new form AndroidModule2 and then just show the AndroidModule2 (Form2.Show). This is what I want. I hope it's clear. Please help me, thanks is advance. ---------------------------------------------------------------------- nicelybrewed · 2025-07-23 08:48 You just need to show the form if it's already created? or do you mean you need to know how to create the form statically within Lazarus using LAMW? If you already have the form created and you just have to show the form with form2.show, just make sure you have set a BackgroundColour on your second form or it will not show. ---------------------------------------------------------------------- Bandy · 2025-07-23 10:35 Yes, I mean I need to know how to create the form statically within Lazarus using LAMW. I just go to File Menu -> New... -> LAMW [GUI] Android jForm? ---------------------------------------------------------------------- nicelybrewed · 2025-07-23 11:16 You will need to add a new 'LAMW [GUI] Android jForm', this will prompt to save/create a .pas file and it should add it to the uses clause of the project.lpr. The issue you're probably running into is that you need to create/initialise the form during runtime before you show it, if you haven't already done this (even if your form is created/exists in your project), you can do this in the OnJNIPrompt event or when you click the button, you can create the form at that point, you can add something like below, then you can call Form2.show. As mentioned previously, make sure you set a background color on the second form, as it defaults to being transparent, you won't see it otherwise. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i If (Form2 = nil) then begin   gapp.CreateForm(TForm2, Form2);   Form2.Init(); end; Then: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form2.show; I personally initialise/create the form at startup and just show/hide the form when I need to, but it depends how often you need to use it I guess, I use it a lot in my project. ---------------------------------------------------------------------- Bandy · 2025-07-23 12:29 It works ok, I just replaced Form2 with AndroidModule2. Now, with AndroidModule 2 shown on the display, I want to return to first form (AndroidModule1) when I tap the return button (<) on the display. How can I do that, please? ---------------------------------------------------------------------- nicelybrewed · 2025-07-23 14:21 Use KEYCODE_BACK to catch your back tap to close AndroidModule2 using the OnSpecialKeyDown event on the AndroidModule2 form: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule2.AndroidModule2SpecialKeyDown(Sender: TObject; keyChar: char;  keyCode: integer; keyCodeString: string; var mute: boolean);beginif (KeycodeString = 'KEYCODE_BACK') then  begin       AndroidModule2.close;    mute := true;   end; end; ---------------------------------------------------------------------- Bandy · 2025-07-23 14:38 It works, thanks! Where can I find help info with examples for developing Android apps? ---------------------------------------------------------------------- nicelybrewed · 2025-07-23 16:15 Glad you got it working. You should have them bundled on your system under the LAMW directory (LazarusModuleWizard) in a directory called 'demos', failing that: https://github.com/jmpessoa/lazandroidmodulewizard/tree/master/demos/G UI https://github.com/jmpessoa/lazandroidmodulewizard/archive/refs/heads/ master.zip ---------------------------------------------------------------------- Bandy · 2025-07-24 08:23 But help files with explanations for Android development/programming where can I find? ---------------------------------------------------------------------- nicelybrewed · 2025-07-24 21:12 The core code is pascal, plenty of documentation on the internet like: https://www.freepascal.org/docs-html/current/ref/ref.html Regards Android development relating to LAMW you need to know how a manifest file is put together, it does helps: https://developer.android.com/guide/topics/manifest/manifest-intro Also knowing how a gradle file is put together is useful to optimise your app for targeting specific devices and Android APIs: https://developer.android.com/build/gradle-build-overview This is a build automation tool, but there are specific tweaks you need to do to the build.gradle file before you add an app to the Google Play Store, or at least you should review what's in the build file before you publish. Some docs here too relating to LAMW: https://github.com/jmpessoa/lazandroidmodulewizard/tree/master/docs