Initialize panel?

jschuchert

Active Member
Licensed User
Longtime User
I created a panel (pnlbrgbrg) with a "intersections" layout for one of my activities but get an error saying the object must be initialized. I am not clear on what is meant. I followed Klaus' example and could not see any separate code for that. Here is my code so far:
B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
Dim txtFrom As EditText 
Dim txtTo As EditText 
Dim txtBearing As EditText 
Dim txtDistance As EditText 
Dim txtDescriptor As EditText 
Dim txtDisplay As EditText 
Dim btnOK As Button 
Dim btnMenu As Button 
Dim btnReset As Button
Dim crd(4)
Dim intq
Dim firstpt,secondpt
Dim pnlbrgbrg As Panel  '[color=red]I thought this initialized it[/color]
Dim btnPanelOK As Button 
End Sub

Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout ("embed")
pnlbrgbrg.LoadLayout("intersections") [color=red]this line throws the error[/color]
pnlbrgbrg.Visible=False
End Sub

The panel will become visible with some other code in the 'embed' activity. The docs say that 'initialize' is one of 'panel's' members with a parameter of 'eventname' but don't know what that refers to. I keep going back to the 'twopanel' activity example by Klaus for my guide. Thanks for any advice and help. This has to be pretty simple.

Jim Schuchert
 

kickaha

Well-Known Member
Licensed User
Longtime User
You need to initialize the panel before you can use it, I suggest:
B4X:
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout ("embed")
pnlbrgbrg.Initialize("pnl")' Initialize with pnl as the event name
pnlbrgbrg.LoadLayout("intersections") 'this line throws the error
pnlbrgbrg.Visible=False
End Sub
The event name parameter (above given as pnl) is the name of the events that this panel will raise, eg if you click the panel it (in the example above) will try to call a sub called pnl_Click.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Thanks, Andy, that at least does not throw an error. However, it doesn't seem to work like a panel in other software I have used. I have several text boxes in the 'embed' activity. When a user clicks the OK button it scans down the code to see if any of the conditions apply. For example, if the 'bearing' text box only has 3 characters, it changes it to 6 with other code. As it scans further it will see this:
B4X:
If txtfrom.Text <>"" AND txtbearing.Text = ""  Then
pnlbrgbrg.Visible=True  
End If

I expected the panel to appear and essentially cover the activity layout but nothing happens.

The panel has additional controls (views) which will come into play and execute other code when I click the btnPanelOK_click button. Anyway, that is what is supposed to happen. But the above code does not display the panel. There will be other variations of the code to compute 3 separate intersection solutions when I leave other text boxes blank and fill in others.

I'm sure you have looked at the panel examples in the docs (not that you need to) so could you explain why they work and mine doesn't, especially concerning the initialization.

Unrelated...when one of my routines ends, it is supposed to add 1 to the contents of the txtFrom box and put the result in the txtTo box. I does it ok but adds .0 to the number. For example, if the txtFrom box has the number 4 in it, then the txtTo box will have 5.0 instead of just 5. Any ideas?

Jim
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Jim,
It would be easier if you post the whole code as a zip file.
You can create it in the IDE menu with 'Export as Zip'.
So we can see how you have added and declared the different Views.

If the panel is added in the Designer you don't need to Initialize it in the code.
But if you add the panel in the code you must first declare it with Dim and then Initialize it with it's Event name (already explained by kickaha).

Best regards.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Klaus, the panel was added in the designer (I never do it by code). I have attached the zip file. A lot of code (from b4ppc) has been commented for later inclusion if I use it.
 

Attachments

  • androidcogo.zip
    31.2 KB · Views: 246
Upvote 0

klaus

Expert
Licensed User
Longtime User
Klaus, the panel was added in the designer (I never do it by code). I have attached the zip file.
I'm afraid that you are mixing up a few things.
You defined the panel in the Designer in the Intersections layout file with the name pnlbrgbrg, but you defined it again with the same name in the Embed module in the code and you load the Intersection layout onto it, but you didn't add the panel onto the Embed activity! The OS treats them as two different panels and unfortunately this doesn't work.

There are two possibilities:
- Define the pnlbrgbrg panel with its views directly in the Embed layout file.
- Keep the Intersections layout file, but instead of adding the views onto a panel put them directly onto the layout activity. In the Embed modul code add the pnlbrgbrg panel to the embed activity and load the new Intersection layout onto the panel.

Attached you find a modified version that works, with the second principle.
I modified the Intersection layout file.

Without the whole code it would have been impossible to help you :), that's the reason why I always ask for the code.

From my experience for having several panels in an activity, I suggest the following:
- Define a seperate layout file for each panel.
- Add the panels in the code
- Load the respective layout files onto the panels.

I had used panels defined with their views directly in the activity, but it's difficult to have a good overview of them so I abandoned doing it that way.

Best regards.
 

Attachments

  • androidcogo_1.zip
    31.4 KB · Views: 333
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Klaus, your modification worked great. Thank you so much. You're absolutely right about my mixing things up. I hope I live long enough to finish this project. b4ppc was a stroll in the park for me compared to b4a but maybe the documentation was much simpler for me to understand. I miss my "goto" crutch and find many familiar expressions have the parameters in a different order. But, I'll just adapt and do my best. If it weren't for you, Andy and others like you, I would have to throw up my hands and surrender. Thanks again.

Jim
 
Upvote 0

Similar Threads

Top