how do I unload a layout...

Discussion in 'Android Questions' started by eben51, Dec 20, 2010.

Thread Status:
Not open for further replies.
  1. eben51

    eben51 Member Licensed 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
     
  2. Cor

    Cor Active Member Licensed User

    activity.finish
     
  3. eben51

    eben51 Member Licensed User

    No that close the the whole activity I just want to swtich from one layout "form" to another, like changing screen within the activity.
     
  4. Cor

    Cor Active Member Licensed User

    then use startactivity(name)

    e.g.

    StartActivity(NoteInput) 'name of module
     
  5. eben51

    eben51 Member Licensed User

    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.
     
  6. eben51

    eben51 Member Licensed 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 :(
     
  7. Cor

    Cor Active Member Licensed 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 :)
     
  8. Erel

    Erel Administrator Staff Member Licensed 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.
    Code:
    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, 00100%x100%y)
    End Sub
     
    amin2dpr and laviniut like this.
  9. eben51

    eben51 Member Licensed User

    thanks,

    Just put the software on my xmas list.
     
  10. MotoMusher

    MotoMusher Active Member Licensed 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.
     
  11. MotoMusher

    MotoMusher Active Member Licensed 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
     
  12. naveenpn

    naveenpn Member Licensed 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.
     
  13. klaus

    klaus Expert Licensed User

    Whithout knowing your code and what you have in the layout files impossible to help you.
    Post your project as a zip file (IDE menu Files / Expost As Zip) so we could look at it.
     
  14. mc73

    mc73 Well-Known Member Licensed User

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

    ovt001 Member Licensed 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
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    1. Please start a new thread for this question.
    2. Please use [code]code here...[/code] tags when posting code.
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice