Android Question Customer Listview on AS Tabstrip

Good day!

I am trying to incorporate the Customer Listview in the AS Tabstrip. I want to know what I'm doing wrong. Please see the code below.

B4X:
#Region  Project Attributes 
    #ApplicationLabel: Tabs-List Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    
End Sub

Sub Globals
    Private xui As XUI
    Private ASTabStrip1 As ASTabStrip
    Type ItemValue (Label1 As Label)
    
    Private clvCO As CustomListView
    Private lblOrderRef As Label
    Private OrderAmount As Label
    Private lblCustomer As Label
    Private lblCustContact As Label
    Private lblDelType As Label
    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private lblStoreAdr As Label
    Dim ImageView1 As ImageView
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("List")
    Dim image As List
    image.Initialize
    
    ASTabStrip1.AddTab("Current_Order", "Current Orders",Null,"")
    ASTabStrip1.AddTab("For_Delivery", "For Delivery", Null,"")
    ASTabStrip1.AddTab("Finished_Orders", "Finished Orders",Null,"")
    ASTabStrip1.AddTab("Order_History", "Order History",Null,"")
    
    For Each f As String In Array("govesmart.png")
    
        image.Add(LoadBitmapResize(File.DirAssets, f, 100dip, 100dip, True))
    
    Next
    
    For i = 1 To 20
        Dim iv As ItemValue
        iv.Initialize
        
        clvCO.Add(CreateItem(image.Get(i Mod image.Size), iv), iv)
    Next
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    
End Sub

Private Sub CreateItem (img As Bitmap, iv As ItemValue) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    
    p.SetLayoutAnimated(0, 0, 0, 100%x, 120dip)
    p.LoadLayout("CurrentOrder_view")
    
    ImageView1.Bitmap = img
    lblOrderRef.Text = "Reference No: 0235"
    OrderAmount.Text = "P 500"
    lblCustomer.Text = "Jon Caesar Basco"
    lblCustContact.Text = "09553174861"
    lblDelType.Text = "Express"
    lblStoreAdr.Text = " STORE ADDRESS: GoveSmart Solutions, Inc.m Luna Street, Lapaz, Iloilo City, Iloilo, Philippines"

    Return p
End Sub
End Sub

Also, below is the error that I am getting.

Logger connected to: HUAWEI STK-L22
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 89 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'int anywheresoftware.b4a.objects.collections.List.getSize()' on a null object reference
at b4a.example3.customlistview._add(customlistview.java:71)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at TabsList.example.main.afterFirstLayout(main.java:105)
at TabsList.example.main.access$000(main.java:17)
at TabsList.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:888)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
** Activity (main) Resume **
 
I'm not familiar with ASTabStrip but it looks like clvCO was not added to any of the layout files.
Yes, it is because clvCO is initialized in layout "Current_Order"

B4X:
ASTabStrip1.AddTab("Current_Order", "Current Orders",Null,"")

Which I don't know how I can get around with.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
java.lang.NullPointerException: Attempt to invoke virtual method 'int anywheresoftware.b4a.objects.collections.List.getSize()' on a null object reference
ASTabStrip1.AddTab("Current_Order", "Current Orders",Null,"")
look at the Example, youre using the class wrong.

  1. Initialize the TabMenu and ViewPager
    1. B4X:
      ASTabStrip1.Initialize(ASTabMenu1,ASViewPager1)
  2. Add a tab
    1. B4X:
          Dim tmp_xpnl As B4XView = xui.CreatePanel("")
              tmp_xpnl.SetLayoutAnimated(0,0,0,ASViewPager1.CustomListView.GetBase.Width,ASViewPager1.CustomListView.GetBase.Height)
              tmp_xpnl.LoadLayout("yourlayout")
              ASTabStrip1.AddPage(xui.Color_ARGB(255,39, 174, 97),"Tab " & i,GetRandomIcon,"",tmp_xpnl,"")
 
Upvote 0
Top