Android Question CustomListView not displaying

Declan

Well-Known Member
Licensed User
Longtime User
The following code does not display the CustomListView - I have included all code in B4XMainPage:
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public  WobbleMenu1 As WobbleMenu
    Public pg1 As B4XPage1
    
    Public ActivePage As String

    Private Panel1 As B4XView
    Private Label1 As B4XView
    Private imgVehicle As ImageView
    Private lblSpeed As B4XView
    Private lblLastDateTime As B4XView
    Private Label2 As B4XView
    Private Label3 As B4XView
    Private lblLat As B4XView
    Private lblLon As B4XView
    Private imgSignal As ImageView
    Private lblSignal As B4XView
    Private imgVolts As ImageView
    Private lblVolts As B4XView
    Private clv1 As CustomListView
    Private imgLogo As ImageView
End Sub

Public Sub Initialize
'    Log("Sub Initialize")
    B4XPages.GetManager.LogEvents = True
    B4XPages.GetManager.ShowUpIndicator = False
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
'    Log("Sub B4XPage_Created")
    B4XPages.GetManager.ShowUpIndicator = False
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "  Invictus")
    
    pg1.Initialize
    B4XPages.AddPageAndCreate("pg1", pg1)

    WobbleMenu1.SetTabTextIcon(1,"Home",Chr(0xF009),Typeface.FONTAWESOME)
    WobbleMenu1.SetTabTextIcon(2,"Devices", Chr(0xF1EB), Typeface.FONTAWESOME)
    WobbleMenu1.SetTabTextIcon(3,"Profile",Chr(0xF2C0),Typeface.FONTAWESOME)
    WobbleMenu1.SetCurrentTab2(1, False)
    clv1.AsView.Visible = False
    Sleep(3000)
    CallSub(Main, "CheckForUser")

    
End Sub

Private Sub B4XPage_Appear
'    Log("Sub B4XPage_Appear")
    B4XPages.GetManager.ShowUpIndicator = False
    B4XPages.SetTitle(Me, "  Invictus")
    ActivePage = "MainPage"
    CallSub2(Main,"getDevices",Main.myFleet)
    getTransLastServer(Main.myFleet)
    WobbleMenu1.SetCurrentTab2(1, False)
    WobbleMenu1.SetVisible(True,False)

    
End Sub

Sub WobbleMenu1_Tab2Click
    B4XPages.MainPage.Pg1.WobbleMenu1.SetCurrentTab(2)
'    B4XPages.ShowPageAndRemovePreviousPages("pg1")
    B4XPages.ShowPage("pg1")
End Sub

Sub getTransLastServer(fleet As String)
'    Log("Sub getTransLastServer")
    Dim msgid As String
    Dim msgdeviceid As String
    Dim msglat As String
    Dim msglon As String
    Dim msgvolts As String
    Dim msgid As String
    Dim msgsignal As String
    Dim msgspeed As String
    Dim msgdatetime As String
    Dim msgfleet As String
    Dim msgfriendname As String
    
'    clv1.Clear
    
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_trans_last", Array(fleet))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        For Each row() As Object In res.Rows
            msgid = row(res.Columns.Get("id"))
            msgdeviceid = row(res.Columns.Get("deviceid"))
            msglat = row(res.Columns.Get("lat"))
            msglon = row(res.Columns.Get("lon"))
            msgvolts = row(res.Columns.Get("volts"))
            msgsignal = row(res.Columns.Get("mysignal"))
            msgspeed = row(res.Columns.Get("myspeed"))
            msgdatetime = row(res.Columns.Get("datetime"))
            msgfleet = row(res.Columns.Get("fleet"))
            msgfriendname = row(res.Columns.Get("friendname"))
            
            Log("***************************")
            Log("msgid: " & msgid)
            Log("msgdeviceid: " & msgdeviceid)
            Log("msglat: " & msglat)
            Log("msglon: " & msglon)
            Log("msgvolts: " & msgvolts)
            Log("msgsignal: " & msgsignal)
            Log("msgspeed: " & msgspeed)
            Log("msgdatetime: " & msgdatetime)
            Log("msgfleet: " & msgfleet)
            Log("msgfriendname: " & msgfriendname)
            Log("***************************")
            
            Dim Transactions As Map
            Transactions.Initialize
            Transactions.Put(1, msgid)
            Transactions.Put(2, msgdeviceid)
            Transactions.Put(3, msglat)
            Transactions.Put(4, msglon)
            Transactions.Put(5, msgvolts)
            Transactions.Put(6, msgid)
            Transactions.Put(7, msgsignal)
            Transactions.Put(8, msgspeed)
            Transactions.Put(9, msgdatetime)
            Transactions.Put(10, msgfleet)
            Transactions.Put(11, msgfriendname)
        
            clv1.Add(CreateListItem(Transactions, clv1.AsView.Width, 85dip), msgfriendname )
        Next
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

Private Sub CreateListItem(Transactions As Map, Width As Int, Height As Int) As B4XView
'    Log("Sub CreateListItem")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("homeitem")
    
    Label1.Text = Transactions.Get(11)
    
    Dim myBattery As Int
    myBattery = Transactions.Get(5)
    If (myBattery >= 39) Then
        imgVolts.Bitmap = xui.LoadBitmap(File.DirAssets, "darkgreen.png")
        lblVolts.Text = (myBattery / 10) & " Volts"
    Else
        If (myBattery < 39) And (myBattery >= 35) Then
            imgVolts.Bitmap = xui.LoadBitmap(File.DirAssets, "green.png")
            lblVolts.Text = (myBattery / 10) & " Volts"
        Else
            If (myBattery < 35) And (myBattery >= 32) Then
                imgVolts.Bitmap = xui.LoadBitmap(File.DirAssets, "yellow.png")
                lblVolts.Text = (myBattery / 10) & " Volts"
            Else
                If (myBattery < 32) Then
                    imgVolts.Bitmap = xui.LoadBitmap(File.DirAssets, "red.png")
                    lblVolts.Text = (myBattery / 10) & " Volts"
                End If
            End If
        End If
    End If
    
    Dim mySpeed As Int
    mySpeed = Transactions.Get(8)
    If (mySpeed < 5) Then
        imgVehicle.Bitmap = xui.LoadBitmap(File.DirAssets, "truck-green.png")
        lblSpeed.Text = "Parked"
    Else
        If (mySpeed > 5) Then ' Change this value later
            imgVehicle.Bitmap = xui.LoadBitmap(File.DirAssets, "truck-red.png")
            lblSpeed.Text = (mySpeed / 10) & " Kmph"
        End If
    End If
    
    lblLastDateTime.Text = Transactions.Get(9)
    
    Dim mySignal As Int
    mySignal = Transactions.Get(7)
    If (mySignal >= 20) Then
        imgSignal.Bitmap = xui.LoadBitmap(File.DirAssets, "Signal-14plus.png")
        lblSignal.Text = "Excellent"
    Else
        If (mySignal < 20) And (mySignal >= 10) Then
            imgSignal.Bitmap = xui.LoadBitmap(File.DirAssets, "Signal-10to14.png")
            lblSignal.Text = "Good"
        Else
            If (mySignal < 10) Then
                imgSignal.Bitmap = xui.LoadBitmap(File.DirAssets, "Signal-2to9.png")
                lblSignal.Text = "Low"
            Else
            End If
        End If
    End If
    
    lblLat.Text = Transactions.Get(3)
    lblLon.Text = Transactions.Get(4)
    Return p
End Sub

Private Sub clv1_ItemClick(Index As Int, Value As Object)
    Log(Index & " = " & Value)
End Sub

Sub CreateRequest As DBRequestManager
'    Log("Sub CreateRequest")
    Dim req As DBRequestManager
    req.Initialize(Me, Main.rdcLink)
    Return req
End Sub

Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
'    Log("Sub CreateRequest")
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters = Parameters
    Return cmd
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

The Log from running above code:
B4X:
Logger connected to:  samsung
--------- beginning of main
*** Service (starter) Create ***
iss.db Exists
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** pg1: B4XPage_Created
B4XPage1: B4XPage_Created
00001
ISS TEST
00002
CUTOUT-TEST
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
***************************
msgid: 1478
msgdeviceid: 00001
msglat: -25.820837
msglon: 28.28895
msgvolts: 44
msgsignal: 23
msgspeed: 000
msgdatetime: 04-May-2023 17:44:37
msgfleet: Invictus
msgfriendname: ISS TEST
***************************
***************************
msgid: 1808
msgdeviceid: 00002
msglat: -25.765227
msglon: 28.31611
msgvolts: 35
msgsignal: 14
msgspeed: 000
msgdatetime: 10-May-2023 17:04:09
msgfleet: Invictus
msgfriendname: CUTOUT-TEST
***************************
Sub CheckForUser
GOT USER
Fleet: Invictus
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
** Service (httputils2service) Destroy **
--------- beginning of system
*** Service (starter) Create ***
iss.db Exists
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** pg1: B4XPage_Created
B4XPage1: B4XPage_Created
00001
ISS TEST
00002
CUTOUT-TEST
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
***************************
msgid: 1478
msgdeviceid: 00001
msglat: -25.820837
msglon: 28.28895
msgvolts: 44
msgsignal: 23
msgspeed: 000
msgdatetime: 04-May-2023 17:44:37
msgfleet: Invictus
msgfriendname: ISS TEST
***************************
***************************
msgid: 1808
msgdeviceid: 00002
msglat: -25.765227
msglon: 28.31611
msgvolts: 35
msgsignal: 14
msgspeed: 000
msgdatetime: 10-May-2023 17:04:09
msgfleet: Invictus
msgfriendname: CUTOUT-TEST
***************************
Sub CheckForUser
GOT USER
Fleet: Invictus
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
** Service (httputils2service) Destroy **
*** Service (starter) Create ***
iss.db Exists
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** pg1: B4XPage_Created
B4XPage1: B4XPage_Created
00001
ISS TEST
00002
CUTOUT-TEST
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
***************************
msgid: 1478
msgdeviceid: 00001
msglat: -25.820837
msglon: 28.28895
msgvolts: 44
msgsignal: 23
msgspeed: 000
msgdatetime: 04-May-2023 17:44:37
msgfleet: Invictus
msgfriendname: ISS TEST
***************************
***************************
msgid: 1808
msgdeviceid: 00002
msglat: -25.765227
msglon: 28.31611
msgvolts: 35
msgsignal: 14
msgspeed: 000
msgdatetime: 10-May-2023 17:04:09
msgfleet: Invictus
msgfriendname: CUTOUT-TEST
***************************
Sub CheckForUser
GOT USER
Fleet: Invictus
 
Solution
1683734068220.png



It doesn't seem to me that you subsequently make it visible.
Top