Android Question [SOLVED] xCustomListView Change Row Color on Click

mmieher

Active Member
Licensed User
Longtime User
This seems simple. When click on a row in a xCustomListView, toggle the "include this" color (purposely not using the word "selected"). Not working. Log showing the correct value of olccSelected(Index).

B4X:
Dim clvOLCCList As CustomListView
...

Sub clvOLCCList_ItemClick (Index As Int, Value As Object)
   
    Log("ItemClick " & olccSelected(Index))
   
    Dim p As B4XView = clvOLCCList.GetPanel(Index)
   
    Dim selColor As Int = Colors.RGB(144,238,144)
    Dim omtColor As Int = Colors.RGB(211,211,211)
   
    If olccSelected(Index) Then
        p.Color = selColor
    Else
        p.Color = omtColor
    End If
   
    p.RemoveViewFromParent
    clvOLCCList.ReplaceAt(Index,p,50dip,Value)

End Sub
 

mmieher

Active Member
Licensed User
Longtime User
Thanks, Peter. That does not work either. Panels do not change color. When I initially create the panel I can change the backcolor just fine. Just not later on.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
How do you fill the CLV? Is there in place another backpanel on which the views are placed?
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Like this ...

B4X:
    iList.Initialize
    SQLText = "SELECT * FROM items ORDER BY mname"
    iList = DBUtils.ExecuteMemoryTable(SQL1,SQLText,Null,0)
   
    For i = 0 To iList.Size - 1
       
        qRecord = iList.Get(i)
        qMap = MapItemRecord(qRecord)
       
        Dim cli As Panel = CreateOLCCItem(qMap.Get("iditem"),qMap.Get("mname"),qMap.Get("msize"),qMap.Get("mprice"), i, clvOLCCList.AsView.Width, 50dip)
        clvOLCCList.Add(cli,qRecord(0))
       
    Next

....
   
Sub CreateOLCCItem(inItem As Int, inName As String, inSize As String, inCost As Double, inIndex As Int, Width As Int, Height As Int) As Panel
   
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0dip, 0dip, Width, Height) 'set the panel size before you load the layout.
    p.LoadLayout("OLCCListPanel")
   
    lbName.Text = inName
    lbSize.Text = inSize
    lbPrice.Text = NumberFormat2(inCost,1,2,2,False)
   
    Dim fTest As Boolean = CheckOLCCItem(inItem)
    If fTest Then
        p.Color = Colors.RGB(144,238,144)
        olccSelected(inIndex) = True
    Else
        olccSelected(inIndex) = False
    End If
    Return p
   
End Sub
 
Upvote 0

udg

Expert
Licensed User
Longtime User
p.LoadLayout("OLCCListPanel") is it based on a back panel? Or anything is placed directly on the activity?
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Solved! Stupid program logic! Sorry for the fire drill. Original method works just fine now.
 
  • Like
Reactions: udg
Upvote 0
Top