Multiple layouts manipulation

jschuchert

Active Member
Licensed User
Longtime User
My application's first screen is a column of buttons serving as a menu of various calculation routines. I named the layout "menu". When a button is selected, a new layout appears with the views for that particular routine. The new layout then has a button to get back to the main menu for selecting other menu items after finishing with the current routine. However, when the menu layout comes up again (which sometimes fails), I am unable to click different buttons to go to another menu item. The next menu item won't activate. Here is an example of the code, leaving out the many globals :

B4X:
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout ("menu")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub btnArea_click
removeviews
activity.LoadLayout ("area") [color=green]' one of the menu items[/color]
StartActivity("area")  [color=red]should this appear here?[/color]
End Sub

Sub btnembed_click
removeviews
activity.loadLayout("embed") [color=green]another menu item[/color]
StartActivity("embed")
 End Sub
 
Sub btnStart_click
removeviews
activity.loadLayout("start") [color=green]'and another [/color]
'StartActivity("start")
 End Sub

 Sub removeviews
 Dim i As Int
 For i=activity.NumberOfViews-1 To 0 Step -1
 activity.removeviewat(i)
 Next 
 End Sub
Everything works fine in accessing the menu item.

The problem appears getting back to the menu and then being able to select a different item as shown in an excerpt from the "area" layout after being activated from the Menu. The other routines act similarly.

B4X:
Sub btnMenu_click
removeviews
activity.loadlayout ("menu")
StartActivity("menu")
End Sub

Sub removeviews
 Dim i As Int
 For i=activity.NumberOfViews-1 To 0 Step -1
 activity.removeviewat(i)
 Next 
 End Sub

[color=red] If this code does return to the main menu, selecting another menu button does nothing.[/color]

Not sure of the significance but the module containing the Menu layout is named "Main". The others are named the same as the layout. Any help will be appreciated. Thank you.

Jim Schuchert
 

kickaha

Well-Known Member
Licensed User
Longtime User
Jim,

I think you have a basic misunderstanding of activities.

If "area" "embed" and "start" are activities (that is they have their own code page with Activity_Create, Activity_Resume, Activity_Pause etc subs) you should not be loading the layouts in the main code, but load them in their own modules. You also do not have to remove the views on the current layout:



B4X:
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout ("menu")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub btnArea_click
removeviews ' [COLOR="Red"]THIS IS NOT NEEDED[/COLOR]
activity.LoadLayout ("area") ' one of the menu items [COLOR="Red"]THIS IS NOT NEEDED[/COLOR]
StartActivity("area")  ' should this appear here? [COLOR="Blue"]YES[/COLOR]
End Sub

Sub btnembed_click
removeviews  ' [COLOR="Red"]THIS IS NOT NEEDED[/COLOR]
activity.loadLayout("embed") another menu item ' [COLOR="Red"]THIS IS NOT NEEDED[/COLOR]
StartActivity("embed")
 End Sub
' and so on
Have a good look at this tutorial by Klaus, he gives a very concise example. Concentrate on the TwoLayoutActivities part (do not mix it up with the TwoActivityLayouts as you seem to have done) and get back to us if you are still stuck.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
To clarify my post (and paraphrasing Klaus), your main module should be structured:

B4X:
Sub Activity_Create(FirstTime As Boolean)
 Activity.LoadLayout("menu")
End Sub
 
Sub Activity_Resume
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Sub btnArea_click
 StartActivity(area)
End Sub

Then your area module:
B4X:
Sub Activity_Create(FirstTime As Boolean)
 Activity.LoadLayout("area")
End Sub
 
Sub Activity_Resume
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Sub Exit_Click ' or your preferred method of exiting
 StartActivity(Main) ' I must admit that I use Activity.Finish here I must check which is best method
End Sub
Add more modules as required.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Andy,

Your answer was perfect. I am now getting a better feel for how to do what I want to accomplish. You and Klaus and Andrew and others are life savers. I can't understand why you are only noted as "Knows the Basics" when you should be IMO close to the "expert" designation. I am actually converting my PPC app to Android. I was quite comfortable with B4PPC but this one is taking much longer to learn. The terms and syntax are quite a bit different and my mind is not as quick anymore so please bear with me a little longer.

Incidentally, which is the best method to go from 'compiled' mode on the emulator to 'designer' mode for making changes, adding views, etc.? I eventually get there by pressing the 'Esc' key but there must be a better way.

I'm now getting into 'Files' (an important part of my app) and have been initially successful so keep your fingers crossed. I am using Klaus' suggestion to use DirInternal and so far that is working but I know I have a long way yet to go.

My application is designed for surveyors and engineers and is centered around 'coordinate geometry'. Points are created which contain values for North and East distances from some point on the earth's surface or from an assumed point. Then various routines (20+) manipulate those points to determine area, new positions, elevations, curve elements, closure of boundaries, etc. I am telling you this so you will have an idea of what I am doing and perhaps the basis for some of my questions.

Thanks again for your assistance.

Jim
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Stop it Jim, you are embarrassing me, but I am happy to have helped!

As far as I know the "knows the basics" is based on your post count.

I dont know the answer to the emulator "feature" as I never use it. There must be some pretty serious maths going on in your app.
 
Upvote 0
Top