Android Tutorial Two activities example

margret

Well-Known Member
Licensed User
Longtime User
Panel Issue


But there are four places that the panels name must be, as indicated in bold above. If you have to use the panel variable name, how does it get passed to the four positions that need it. As I stated I want this code to work for how every many panels I wish to popup and to not replicate this code for each. I will try what you said. I am changing the code and will report back. The error listed below is what you get when you send the panel to the sub. Looks like the only way it will work is to send the panel name and then have it macro substituted.

Compiling code. Error
Error compiling program.
Error description: Unknown member: height
Occurred on line: 376
mh1=(pnlSelect.Height/2) - (panelname.Height/2) + hc
Word: height

Thanks,

Margret
 
Last edited:

kickaha

Well-Known Member
Licensed User
Longtime User
No, there are 4 places where the Panel should be, hence send the panel.

As an aside, it is good practice to tell the sub what types it is receiving:
B4X:
Sub PanelPop ( panelname As Panel, mlayout As String, hc As Int, wc As Int)

That way, when you type in the subs name you are reminded what you should be sending, and the sub does not default everything to strings.
 

margret

Well-Known Member
Licensed User
Longtime User
Panel Issues


I did as you said and the program complied fine. Then I loaded in the tablet and when you run the code to pop up the panel, I get the error that Object should be initialized (Panel).

If there were options for macros this would be done. But I understand that option is not in B4A, so, any ideas of how to make this work?

Thanks,

Margret
 

kickaha

Well-Known Member
Licensed User
Longtime User
Is the Panel that you are sending it initialized in code before you call this sub?

The sub should work, can you single step through it with the debugger and let us know what value panelname has got?
 

kickaha

Well-Known Member
Licensed User
Longtime User
Also, the panel you are sending to the sub needs to be added to a layout first, otherwise height and width make no sense!
 

margret

Well-Known Member
Licensed User
Longtime User
Panel Issues

Also, the panel you are sending to the sub needs to be added to a layout first, otherwise height and width make no sense!

If I change the name in four places that was marked bold from panelname to panelweb(panelweb is the real name of the panel in the layout file) the code runs fine and bring up the panel and all works just as it should. This ignores the panelname parameter passed to the sub, but everything works. Under sub globals I have Dim panelweb As Panel. This is driving me crazy. I felt like I was moving through this pretty good and then brick wall.

Thanks,

Margret
 
Last edited:

kickaha

Well-Known Member
Licensed User
Longtime User
Is panelweb in the layout you are sending to the sub (mlayout)? If it is, is it the only panel on the layout(s) that you want to pop up?
 

margret

Well-Known Member
Licensed User
Longtime User
Panel Issue

Is panelweb in the layout you are sending to the sub (mlayout)? If it is, is it the only panel on the layout(s) that you want to pop up?

Yes it is in the layout file I'm sending (mlayout) and yes, it is the only panel to display and the only panel in the layout file, the .bal. You have the code sniplet, and I was going to attached the layout file in a zip but this forum will not upload the zip file. If you PM me I will email the zip file with the layout.

Thanks,

Margret
 

kickaha

Well-Known Member
Licensed User
Longtime User
Try this, it will work if the layout only has one Panel on it. Note you do not need to send the panel to PanelPop as it finds it now.

B4X:
Sub PanelPop (mlayout As String, hc As Int, wc As Int)
   Dim panelname As Panel
   Dim out As Boolean : out = False
   Dim pointer As Int : pointer = 0

   pnlSelect.Initialize ( "Select")      
   pnlInput.Initialize ("")
   pnlInput.LoadLayout ( mlayout ) 
   
   Do While out = False
      If pnlInput.GetView (pointer) Is Panel Then
         out = True
         panelname = pnlInput.GetView (pointer)
      Else
         pointer = pointer + 1
         If pointer = pnlInput.NumberOfViews Then out = True
      End If
   Loop
   if pointer = pnlInput.NumberOfViews Then Return' error has occured no panel found
   pnlSelect.Color  = Colors.ARGB (150,0,0,0)         
   Activity.AddView (pnlSelect, 0, 0,   100%x, 100%y)   
   mh1=(pnlSelect.Height/2) - (panelname.Height/2) + hc
   mw1=pnlSelect.Width/2 - (panelname.Width/2) + wc
   mh2=panelname.Height
   mw2=panelname.Width
   pnlSelect.AddView (pnlInput, mw1, mh1, mw2, mh2)
   'Example: edittexturl.Text=HomePage
End Sub
 

margret

Well-Known Member
Licensed User
Longtime User
Panel Issue


The problem is that this screen layout only has one. The other layouts I have has more than one panel to group different sets of radio buttons. I did not see where you could just add a container. Now the debugger has stopped working with no errors, the only thing I did was add some libraries. I try to start in debug mode and it just closes and with no errors. I get the same on the AVD. I spent the time to setup a new machine, fresh install and it does the same thing.
 

kickaha

Well-Known Member
Licensed User
Longtime User
I have just had a thought, is the panel you are getting the size of ONLY there to define the size of the pop-up on each layout?

If that is the case, give them the same name ON EVERY LAYOUT.

This will work, as the code will reference the last defined one when you invoke it. If we name them all sizepanel your code would then be
B4X:
Sub PanelPop (mlayout As String, hc As Int, wc As Int)

   pnlSelect.Initialize ( "Select")      
   pnlInput.Initialize ("")
   pnlInput.LoadLayout ( mlayout ) 
   pnlSelect.Color  = Colors.ARGB (150,0,0,0)         
   Activity.AddView (pnlSelect, 0, 0,   100%x, 100%y)   
   mh1=(pnlSelect.Height/2) - (sizepanel.Height/2) + hc
   mw1=pnlSelect.Width/2 - (sizepanel.Width/2) + wc
   mh2=sizepanel.Height
   mw2=sizepanel.Width
   pnlSelect.AddView (pnlInput, mw1, mh1, mw2, mh2)
   'Example: edittexturl.Text=HomePage
End Sub
Do not forget to Dim it in globals!

Sorry, can offer no help on the debugger.
 

margret

Well-Known Member
Licensed User
Longtime User
Panel Issue


I think your on to something! I believe that will work and do what is needed. I went to a backup of the code from last Friday and it runs fine in the debugger. Now I have to find out what in the code brakes a debugger. I have added over 1,000 lines of code from Friday. Well now I know it's in the code somewhere related to the API calls. I will try the other code and report back.

Thank You,

Margret
 

margret

Well-Known Member
Licensed User
Longtime User
Panel Issue

B4X:
Sub PanelPop (mlayout As String, hc As Int, wc As Int)

   pnlSelect.Initialize ( "Select")      
   pnlInput.Initialize ("")
   pnlInput.LoadLayout ( mlayout ) 
   pnlSelect.Color  = Colors.ARGB (150,0,0,0)         
   Activity.AddView (pnlSelect, 0, 0,   100%x, 100%y)   
   mh1=(pnlSelect.Height/2) - (sizepanel.Height/2) + hc
   mw1=pnlSelect.Width/2 - (sizepanel.Width/2) + wc
   mh2=sizepanel.Height
   mw2=sizepanel.Width
   pnlSelect.AddView (pnlInput, mw1, mh1, mw2, mh2)
   'Example: edittexturl.Text=HomePage
End Sub

This did work but I now have a new problem with this. I am using a WebView for the main activity. If a webpage with a flash object is being viewed and you pull up one of these panels, the flash object is on top of the panel. I have tried most everything I could think of and the flash object is still on top. It's like the flash object has an all ways on top setting. Any ideas how to correct this?

Thanks,

Margret
 

kickaha

Well-Known Member
Licensed User
Longtime User
So happy that it is now working.

I have not got a clue about the webview issue, you need the real experts for that one!

I suggest you start a new thread with the question so that it does not get overlooked.
 

Widget

Well-Known Member
Licensed User
Longtime User
I downloaded the TwoActivities.zip file from the link in the tutorial, but the Designer shows no views in the activity for any of the screens. In other words the designer is blank. If I compile the app, it will ask me to save the blank layout. I cancel the save and when the app runs, it runs fine, showing the button and listview. The app works ok. But why doesn't the designer show the views?

Widget
 

Widget

Well-Known Member
Licensed User
Longtime User
In the Designer you must select a layout file if there are more than one file.

Klaus,
Thanks. I finally realized that I have to select File > layout in the Designer. It just wasn't intuitive.

I think it would be more obvious if the Designer had a Layout combo box above the Views combo box. That way I can easily select the Layout and then see the Views within that layout. This would be more hierarchical and the developer would have immediate access to the layouts (scroll through them) instead of going up to the File menu.

:sign0163:

Widget
 

Ramirez

Member
Licensed User
Longtime User
Sorry to up this thread, but I'm French and I'm not sure to undestand :signOops:

If an activity call another one, the second activity is launched and the first is paused ? If the system need free memory at this time, is the first activity deleted from memory or not ?

Thanks.
 

AscySoft

Active Member
Licensed User
Longtime User

+1 Subscribe to that...Designer need to be "redesign" ... no rush but please do so! Also integration into main IDE will be nice (I'm working with many projects at once, for my learning, and is hard not to mess things up)
Sorry for the offtopic.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…