how do I unload a layout...

Status
Not open for further replies.

eben51

Member
Licensed User
Longtime User
Sub button2_click
(code to unload layout2 here???)

Activity.LoadLayout ("layout1")
End Sub

Sub button1_click

(code to unload layout1 here???)

Activity.LoadLayout ("layout2")
End Sub
 

eben51

Member
Licensed User
Longtime User
then use startactivity(name)

e.g.

StartActivity(NoteInput) 'name of module

not really following this, I have a trail verson wanting to see this program is going to do what I want to before I buy it. The trail verson come with little to no documentation, and you can't creat a module within it.

right with code about (mins the part unloading) I can a second layout to open, but it opens on top the first one. I just want to blow the way the first one some how.
 
Upvote 0

eben51

Member
Licensed User
Longtime User
Well, it looks like this trial version isn't going to let me do this, I was hoping to two layouts under one activity cause it's all the trial version lets you have one activity, not two...grr annoying, they should made the trial version do everything except buid the .ark file, like a student copy of vb does :(
 
Upvote 0

Cor

Active Member
Licensed User
Longtime User
Just click on my link at the bottom of this message, to see what is possible
with basic4android

I have made this with basic4android in a couple of weeks
not knowing anything about java, and android programming

or go to android market and search for READY4MUSIC
and install the guitar chords program.

Look at the home page of basic4android
Now sold at a special introductory price: $39 (regular price $69)

maybe this helps :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can load the layout to a panel and then add this panel to the activity.
Later you can remove the existing panel and create a new one with a new layout.
B4X:
Sub Globals
 Dim Panel1 As Panel
End Sub
Sub Activity_Create (FirstTime As Boolean)
 LoadLayoutToPanel("layout1")
End Sub

Sub LoadLayoutToPanel (Layout As String)
 If Panel1.IsInitialized then
   Activity.RemoveViewAt(0)
 End If
 Panel1.Initialize("")
 Panel1.LoadLayout(Layout)
 Activity.AddView(Panel1, 0, 0, 100%x, 100%y)
End Sub
 
Upvote 0

MotoMusher

Active Member
Licensed User
Longtime User
I think this is just what I needed. I added a settings button to the basic Hello World turtorial, to take me to a different "page". This solution above works perfectly (I had both layouts over top of each other previously).

However, when I hit the back arrow in the AVD, it just closes the app completely, rather than return to the hello world page as I would expect. Can I catch that event somehow or do I need a different structure? . Would the proper way to go be to create a second activity instead of this view method? This is my first mobile app.

Great product so far.
 
Upvote 0

MotoMusher

Active Member
Licensed User
Longtime User
Never mind. I found the answer. To future lurkers:

I abandoned the strategy above, and went with a second activity. In the button event to get to the second activity, I used this instead StartActivity("settings"). Now back button works fine.

Found in this tutorial (Sorry, it won't let me post a link)
19514-problems-app-closing-back-button-press-tutorial
 
Upvote 0

naveenpn

Member
Licensed User
Longtime User
I used Erel's suggestion above. When I load the 1st layout, it works fine. But when I try to load the 2nd layout, I get an error:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I tried, adding Activity.RemoveView right after the Activity.RemoveViewAt(0) in the If condition, however, it still gives the same error.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I used Erel's suggestion above. When I load the 1st layout, it works fine. But when I try to load the 2nd layout, I get an error:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I tried, adding Activity.RemoveView right after the Activity.RemoveViewAt(0) in the If condition, however, it still gives the same error.

Inside the if, try
B4X:
panel1.removeView
. Seems to me that your first element of the activity is not panel1, thus this error appears.
 
Upvote 0

ovt001

Member
Licensed User
Longtime User
Sorry that I re-open this post but I have the same problem. I try the solution of mc73, but still not work.
Error message is: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Hier my code:
Sub Globals
Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("frmMainNVision")
LoadLayoutToPanel("frmMainNVision")

End Sub

Sub LoadLayoutToPanel (Layout As String)
If Panel1.IsInitialized Then
Panel1.RemoveView()
End If
Panel1.Initialize("")
Panel1.LoadLayout(Layout)
Activity.AddView(Panel1, 0, 0, 100%x, 100%y)
End Sub
 
Upvote 0
Status
Not open for further replies.
Top