Subpage listview doesn't show

SpaceCow

Member
Licensed User
Longtime User
Hi,

I have the basic code as shown below:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim Panel1, Panel2 As Panel
   Dim TabHost1 As TabHost
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   
   'Tabs
   TabHost1.AddTab("Page 1", "Page1")
   
   'Listview Panel 2
   Panel2.Initialize("Panel2")
   ListView1.Initialize("ListView1")
   Panel2.AddView(ListView1, 0, 0, 100%x, 100%y)
   ListView1.AddTwoLines("test", "test")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
   Panel1.LoadLayout("Page2")
End Sub

Why doesn't Panel2 show the ListView1?

And why doesn't Panel2 fully cover Panel1? Should I close Panel1 first?

Thanks!
 

Attachments

  • henk.zip
    7.3 KB · Views: 157

kickaha

Well-Known Member
Licensed User
Longtime User
Not tried your app so I dont know about the covering problem, but if you have added Panel1 and Panel2 as part of the layouts, you should not initialize them.
 
Upvote 0

SpaceCow

Member
Licensed User
Longtime User
Not tried your app so I dont know about the covering problem, but if you have added Panel1 and Panel2 as part of the layouts, you should not initialize them.

Then i keep getting this error: LastException java.lang.RuntimeException: Object should first be initialized (Panel).

That is on this line: Panel2.AddView(ListView1, 0, 0, 100%x, 100%y)
 
Upvote 0

admac231

Active Member
Licensed User
Longtime User
When you are doing this:
B4X:
    'Listview Panel 2
    Panel2.Initialize("Panel2")
    ListView1.Initialize("ListView1")
    Panel2.AddView(ListView1, 0, 0, 100%x, 100%y)
    ListView1.AddTwoLines("test", "test")
You are initializing Panel2 then adding ListView1 to it. Later on, at this part:
B4X:
Sub Button1_Click
    Panel1.LoadLayout("Page2")
End Sub
You are loading up the Page2.bal layout file. This reinitializes Panel2, and thus removes anything you put in it previously. If you were to load the Page2.bal file up then add ListView1 to it it will work fine:
B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim Panel1, Panel2 As Panel
   Dim TabHost1 As TabHost
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   
   'Tabs
   TabHost1.AddTab("Page 1","page1.bal")
   
   'Listview Panel 2
   ListView1.Initialize("ListView1")
   ListView1.AddTwoLines("test", "test")
   Panel2.Initialize("Panel2")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
   Panel1.LoadLayout("Page2")
   Panel2.AddView(ListView1, 0, 0, 100%x, 100%y)
End Sub
 
Upvote 0

SpaceCow

Member
Licensed User
Longtime User
But I still have that other question.

When I click the button and change the panel, then click on the tab, Panel2 appears. I want to return to Panel1 like before it changed.

What is the easiest way to do that?
 
Upvote 0
Top