Android Question Updating Labels in CustomListView

icakinser

Member
Licensed User
Hi everyone! I have a customlistview loaded with panels that have three labels in them.

How do I update the text of each label in the panel?

This is the method i used to populate the list view:
B4X:
For k = 0 To response.Size - 1
                Dim op As alpacaPosition = response.Get(k)
                Dim p As Panel
                p.Initialize("")
                p.SetLayout(0, 0, CustomListView2.AsView.Width, 75dip)
                p.LoadLayout("Item")
                lbl_symbol.Text = op.symbol & " (" & NumberFormat2(op.currentPrice,1,2,2,True) & ")"
                'Check if there is a loss
                If IsNegative(op.unrealizedIntradayPL) Then
                    
                    lbl_profit_loss.Text = "$(" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True) & ")"
                    p.Color = xui.Color_Red
                    
                Else
                    
                    lbl_profit_loss.Text = "$" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True)
                p.Color = xui.Color_Green   
                End If   
                
                lbl_Qty.Text = NumberFormat2(op.quantity,1,2,2,True)
                CustomListView2.Add(p,op.symbol)

            Next
 

icakinser

Member
Licensed User
I can only find how to update a control if another control has been clicked :( If i cycle through the CustomListView is it possible to update the label I need?
 

mangojack

Well-Known Member
Licensed User
You should have at least posted your attempted effort for someone to guide / correct you as suggested above. ;)

B4X:
Sub clv1_ItemClick(Index As Int, Value As Object)   
    Dim pnl As B4XView = clv1.GetPanel(Index)
    pnl.GetView(0).Text = "abc123"   'view(0) = 1st label on panel.. refer order in Designer ViewTree for Item/Row layout
    '...........
 

icakinser

Member
Licensed User
Sorry my Internet took a poopy. I used
B4X:
For k = 0 To response.Size - 1
                Dim op As alpacaPosition = response.Get(k)
                
                Dim pnl As B4XView = clv1.GetPanel(k)
                pnl.GetView(0).Text = op.symbol & " (" & NumberFormat2(op.currentPrice,1,2,2,True) & ")"               
                'Check if there is a loss
             If IsNegative(op.unrealizedIntradayPL) Then
                    
                    pnl.GetView(1).Text = "$(" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True) & ")"
                   ' p.Color = xui.Color_Red
                    
                Else
                    pnl.GetView(1).Text = "$" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True)
                
                   'p.Color = xui.Color_Green   
               
              End If   
                
                pnl.GetView(2).Text = NumberFormat2(op.quantity,1,2,2,True)
                
            Next
Still clunky and very slow
 

icakinser

Member
Licensed User
Here is my finished sub for those who need it:
B4X:
    If first_time = True Then
    If httpCode = alpaca.HTTP_CODE_OK Then
        'addMemo("List open positions: Success! Items retrieved: " & response.Size)
        For k = 0 To response.Size - 1
            Dim op As alpacaPosition = response.Get(k)
            Dim p As Panel
            p.Initialize("")
            p.SetLayout(0, 0, CustomListView2.AsView.Width, 75dip)
            p.LoadLayout("Item")
            lbl_symbol.Text = op.symbol & " (" & NumberFormat2(op.currentPrice,1,2,2,True) & ")"
            'Check if there is a loss
            If IsNegative(op.unrealizedIntradayPL) Then
                    
                lbl_profit_loss.Text = "$(" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True) & ")"
                p.Color = xui.Color_Red
                    
            Else
                    
                lbl_profit_loss.Text = "$" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True)
                p.Color = xui.Color_Green
            
            End If
                
            lbl_Qty.Text = NumberFormat2(op.quantity,1,2,2,True)
            
            CustomListView2.Add(p,op.symbol)
Next
            alpaca.fetchAccount
        End If
    
    Else
        If httpCode = alpaca.HTTP_CODE_OK Then
        'addMemo("List open positions: Success! Items retrieved: " & response.Size)
        For k = 0 To response.Size - 1
        Dim op As alpacaPosition = response.Get(k)
        Dim pnl As B4XView = CustomListView2.GetPanel(k)
                pnl.GetView(0).Text = op.symbol & " (" & NumberFormat2(op.currentPrice,1,2,2,True) & ")"
                
        'Check if there is a loss
        If IsNegative(op.unrealizedIntradayPL) Then
                    
                    pnl.GetView(1).Text = "$(" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True) & ")"
            pnl.Color = xui.Color_Red
                    
        Else
                    
                    pnl.GetView(1).Text = "$" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True)
            pnl.Color = xui.Color_Green
            
        End If
                
                pnl.GetView(2).Text = NumberFormat2(op.quantity,1,2,2,True)
        Next
            
            
        
        End If
            
End If
You don't need to use the Click event as long as you can cycle through the index array. Runs pretty quick in release mode. But gets a lil slow after about 200 panels.
 
Top