B4J Question B4J - Custom list View

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I am trying to create a custom list view with various views such as combo Boxes, text fields solor pickers:
The code in question is:

Custom List Add Item:
Sub Class_Globals
    ...
    Private  graphSetupRec As graphSetupRec_t
    Private  graphSetupList As List ...
End Sub

'======================================================================================
Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
    cmboGraphGroupMap.Initialize
    graphGroupRec.Initialize
    graphSetupList.Initialize
End Sub


'======================================================================================
Sub CreateGraphSetupListItem As Pane
    Dim p As AnchorPane
    p.Initialize("")
    p.LoadLayout("cvGraphSetups.bjl")

    'Set fields from data base list'
    lblID.Text = graphSetupRec.ID
    txtXgTitle.Text = graphSetupRec.title ...
    ...
    cbShowXUnits.Checked = graphSetupRec.showXUnits
    Return p
End Sub


'======================================================================================
Private Sub getGraphSetupRecords(grpID As Int) As ResumableSub
    Dim req As DBRequestManager = CreateRequest(rdcLink)
    Dim cmd As DBCommand
    graphSetupList.Clear

    Try
        ' Get the Graph Setup Data Set for the Current Garph Group ID
        cmd = CreateCommand("getGraphSetup", Array As String(grpID))

        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)


            Process the results
            For Each row() As Object In res.Rows
                Private  graphSetupRec As graphSetupRec_t
                graphSetupRec.Initialize
               
                graphSetupRec.ID                = row(0) ...
                ...
                graphSetupRec.showXUnits        = intToBool(row(32))
               
                graphSetupList.Add(graphSetupRec)
               
                ' Add to custom list view of Graph Setups
                cViewGraphSetups.Add(CreateGraphSetupListItem, 185)
            Next
        Else
            Return False
            Log("ERROR: " & j.ErrorMessage)
        End If
   
        j.Release
        Return True
    Catch
        Log(LastException)
        Return False
    End Try
End Sub

There are two records picked up in the graphSetupList and the list iterates around the for-next loop twice as expected, but I don't end up with two items in my custom list view, viz:

CustomListView.png



The item added is showing the second record of the graphSetupList.

I looked at a B4A example that I wrote which worked, but the syntax is a bit different in B4J and I couldn't find an example using a custom list view. The libraries I am using are:

CustomListViewLibs.png



I also didn't know what to put as the second parameter:

B4X:
cViewGraphSetups.Add(CreateGraphSetupListItem, 185)

So I just put the height of the custom panel in.

It's obviously something simple can someone help?

Best regards
Rob

I fixed it I forgot to set the size of the panel.

B4X:
    p.LoadLayout("cvGraphSetups.bjl")
    p.SetSize(1000, 185)

It's hard to get good help these days

RJG
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
I looked at a B4A example that I wrote which worked, but the syntax is a bit different in B4J and I couldn't find an example using a custom list view.
The syntax is identical once you learn how to use XUI and B4XView.

Specifically never use AnchorPane.

Correct way to create a panel with layout for the CLV
B4X:
Dim pnl As B4XView = XUI.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, CLV.AsView.Width, 100dip) 'change the height as needed
pnl.LoadLayout("layoutfile")
 
Upvote 0
Top