4. Fill the views
To make use of all the designer views you have to write some code.
Did you generate the members from the layouts already? Yes? Good. No? Do it now then.
In the designer go to the menu Tools / Generate Members.
For the MainPage layout check the views lblbalance, lblcurrency and th1.
For the tab1_layout check the views clv1, lbltotalexpense and sbtn1. Also check the clv1 ItemClick event and the sbtn1 Click event.
For the tab2_layout check the views clv2, lbltotalearning and sbtn2. Also check the clv2 ItemClick event and the sbtn2 Click event.
In the code editor from the B4XMainPage tab you can see that the members were added.
But in the Logs pane on the right we get warnings about these variables.
These warnings tell us what we have to do: assign values and use the layout files.
Delete the button1_click subroutine (the one with the Hello world!" message).
In the B4XPage_Created subroutine we add the TabHost (th1) layouts and fill the labels with some value.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
th1.AddTab("expenses","tab1_layout")
th1.AddTab("earnings","tab2_layout")
lblcurrency.Text = "Balance (EUR)"
lblbalance.Text = 0
lbltotalexpense.Text = 0
lbltotalearning.Text = 0
End Sub
And by doing this the warnings are gone!
Every time the app starts we want the listviews (clv1 and clv2) to be filled with items.
Create the page related event subroutine B4XPage_appear. Click above the message about this and type private sub and press the spacebar and the tab-key.
In the context menu click on B4XPagesManager and press enter. In the next context menu click on Appear and press enter.
A subroutine is created. Replace the EventName with B4XPage and you have a B4XPage event subroutine.
In this B4XPage_appear subroutine we call 2 subroutines to fill the listviews.
Create the subroutines and write a for loop to add text items to the listview (clv1.AddTextItem, clv2.AddTextItem).
Here is the code:
private Sub B4XPage_Appear
fill_clv1
fill_clv2
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub fill_clv1
For i = 1 To 20
clv1.AddTextItem("item " & i,i)
Next
End Sub
Private Sub fill_clv2
For i = 1 To 15
clv2.AddTextItem("item " & i,i)
Next
End Sub