Hi - I have moved the CustomListView code from the CLVExample into a new B4XPage class in the same project (as I want the listview in a page that isn't the main page), however I am receiving and error. Where have I gone wrong?
pgUpcompingDates is using layouts identical to CLVExample, copied and pasted into this project.
The application loads, and Button 1 on MainPage is visible.
Many thanks
Philip
B4XMainPage:
Sub Class_Globals
Private Root As B4XView
Public p_UpcomingDates As pgUpcomingDates
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
p_UpcomingDates.Initialize
B4XPages.AddPage("p_UpcomingDates", p_UpcomingDates)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
'B4XPages.ShowPageAndRemovePreviousPages("UpcomingDates")
B4XPages.ShowPage("p_UpcomingDates")
p_UpcomingDates.LoadList
End Sub
pgUpcompingDates is using layouts identical to CLVExample, copied and pasted into this project.
pgUpcomingDates:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private clv1 As CustomListView
Private clv2 As CustomListView
Private dd As DDD
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
dd.Initialize
xui.RegisterDesignerClass(dd)
Root.LoadLayout("lyoUpcomingDates")
End Sub
Private Sub CreateListItem(Text As String, Width As Int, Height As Int) As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, Width, Height)
p.LoadLayout("CellItem")
'Note that we call DDD.CollectViewsData in CellItem designer script. This is required if we want to get views with dd.GetViewByName.
dd.GetViewByName(p, "Label1").Text = Text
Return p
End Sub
Public Sub LoadList
For i = 1 To 20
clv1.Add(CreateListItem($"Item #${i}"$, clv1.AsView.Width, 60dip), $"Item #${i}"$)
Next
End Sub
The application loads, and Button 1 on MainPage is visible.
Error Block:
[Application Load]
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
[MainPage->Button 1 Click]
*** p_upcomingdates: B4XPage_Created [mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
*** p_upcomingdates: B4XPage_Appear [mainpage]
Error occurred on line: 256 (DDD)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asLabelWrapper(B4XViewWrapper.java:213)
at anywheresoftware.b4a.objects.B4XViewWrapper.setText(B4XViewWrapper.java:229)
at nz.co.tapertech.tvfbstaff.pgupcomingdates._createlistitem(pgupcomingdates.java:114)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7892)
at android.widget.TextView.performClick(TextView.java:16219)
at android.view.View.performClickInternal(View.java:7869)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:30880)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Many thanks
Philip