B4J Question CustomListView - tag without value

DarkoT

Active Member
Licensed User
Hi, need help for CustomList view... I'm filling custom listview with data from my sql database...
I can not understand why is stored Tag empty... Any suggestion...

My code:

1. Creating the x panels with data from my sql (table customers)::
' napolnimo combo z kupci
Sub FillComboCustomer(Filter As String)

    Query = $"select cu_code, cu_name, cu_country from cu "$
  
    If Filter <> "" Then
        Query = Query & " where cu_name like '%" & Filter & "%' and cu_discontinued = '0' order by cu_code "
    Else
        Query = Query & "where cu_discontinued = '0' order by cu_code "
    End If
                    
    Dim rs As ResultSet = OptimusComm.MySql.ExecQuery(Query)
    Dim recKupec As typKupci
    recKupec.Initialize
    Dim i As Int = 0
  
    Do While rs.NextRow
        Dim p As B4XView = xui.CreatePanel("")
        p.Color = xui.Color_Transparent
        p.SetLayoutAnimated(0,0,0, clvKupci.AsView.Width, 30dip)
        recKupec.Sifra = rs.GetString("cu_code")
        recKupec.Naziv = rs.GetString("cu_name")
        recKupec.Drzava = rs.GetString("cu_country")
        p.Tag = i
        i = i + 1
        clvKupci.Add(p, i)
    Loop
    rs.Close
  
End Sub

Filling only visible records with data:
Private Sub clvKupci_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
  
    Dim ExtraSize As Int = 20
    For i = 0 To clvKupci.Size - 1
        Dim pnl As B4XView = clvKupci.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            If pnl.NumberOfViews = 0 Then
                Log(pnl.Tag) ' --> here is tag.value stored
                pnl.LoadLayout("lstKupec")
                Log(pnl.Tag)  ' --> tag.value is empty
                Dim tSifra As TextField = pnl.GetView(0)
                tSifra.Text = pnl.Tag
            End If
        Else
            'Not visible -
            If pnl.NumberOfViews > 0 Then pnl.RemoveAllViews '<--- remove the layout
        End If
    Next

End Sub
 
Solution
Okey... now is clear... Thank you...

DarkoT

Active Member
Licensed User
The custom view have tag on base.
es. pnl.base.tag
Are you sure? I'm getting a error when I want to use pnl.base.tag...

I solve the problem (it's for me not logical, but it work's)...
Can't understand why can use a taged value before loading layout...

Sample - using tag before loading layout?!:
Private Sub clvListKupci_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)

    Dim ExtraSize As Int = 10
    For i = Max(0,FirstIndex -ExtraSize) To Min(LastIndex + ExtraSize, clvListKupci.Size -1)
        Dim pnl As B4XView = clvListKupci.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            If pnl.NumberOfViews = 0 Then
                Dim recKupec As typKupci = pnl.Tag
                pnl.LoadLayout("lstKupec")
                Dim tSifra As Label = pnl.GetView(0)
                tSifra.Text = recKupec.Sifra
                Dim tNaziv As Label = pnl.GetView(1)
                tNaziv.Text = recKupec.Naziv
                Dim tDrzava As Label = pnl.GetView(2)
                tDrzava.Text = recKupec.Drzava
            End If
        Else
            'Not visible -
            If pnl.NumberOfViews > 0 Then pnl.RemoveAllViews '<--- remove the layout
        End If
    Next
    
End Sub
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
If you want to get the tag of an customlistview you must getbase.

for example:

set tag in designer ...

customlistview1.getbase.tag

or i don't understand your problem.
 
Upvote 0

DarkoT

Active Member
Licensed User
If you want to get the tag of an customlistview you must getbase.

for example:

set tag in designer ...

customlistview1.getbase.tag

or i don't understand your problem.
I want to set tag to PANEL, not to customlistview.... And the system works when I store the value in Tag and use BEFORE i load the layout.... After loading the layout tag is empty... Please - see my code below, you will see where is the problem; as I say before - I solve the problem but I can not understand why is working
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Regarding your post #1 there's something wrong about the fact you dim and initialize recKupec outside the loop which reads back the records from the query result. And you don't load any layout for a newly created panel.
Anyway, you question is about pnl.tag in rows 8 and 10 of the second code paragraph.
That happens because when you load a layout for the panel (row 9) it takes with itself its own tag (empty), which substitute the one you printed on row 8.

So, what I would suggest is to:
- move the recKupec inizialization soon before its use (row 21)
- insert a loadlayout for the newly created panel (after row 20)
 
Upvote 1

DarkoT

Active Member
Licensed User
Okey... now is clear... Thank you...
 
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…