B4J Question Built in xCustomlistview error on Displaying Material Icon and looking for quick way to get correct INDEX

Peter Lewis

Active Member
Licensed User
Longtime User
Hi

I have a xCustomlistview which I want to put in a Material ICON. I have managed to display it but i have to repeat the code twice for it to display correctly or it just displays a small square box, As can been seen in the code below.

I also need to find one of the Rows and change the Material Icon. the only way I can find out how to do it is to loop thru all the records until I get the one that matches my variable which is the Value.
This does take time and I do not want to refresh the list all the time. With only a few records in this is , it is not a problem. But when I add 20 records with Pictures . to display it slows down quite quickly.

If there could be a command like clv.GetIndex(Value) would be perfect. If i could click the row in the list I would use CLV_ItemClick

Thank you


B4X:
Public Sub messagestatus (messagedts As Long, Server As Boolean, Delivered As Boolean, Viewed As Boolean)
    For x = 0 To CLV.Size-1
       Dim pnl As B4XView = CLV.GetPanel(x)
        If messagedts = CLV.GetValue(x)  Then
            If pnl.NumberOfViews >2 Then
                Dim lbl As B4XView=pnl.GetView(2)
            
                If Server = True Then
                    lbl.Font = fx.CreateMaterialIcons(15)
                    lbl.SetTextAlignment("BOTTOM","RIGHT")
                   iv.Text = Chr(0xE876)
                    lbl.TextColor=Main.xui.Color_DarkGray
                
                    lbl.Font = fx.CreateMaterialIcons(15)
                    lbl.SetTextAlignment("BOTTOM","RIGHT")
                    iv.Text = Chr(0xE876)
                    lbl.TextColor=Main.xui.Color_DarkGray
                End If
                
                If Delivered = True Then
                    lbl.Font = fx.CreateMaterialIcons(15)
                    lbl.SetTextAlignment("BOTTOM","RIGHT")
                     iv.Text = Chr(0xE877)
                    lbl.TextColor=Main.xui.Color_DarkGray
                
                    lbl.Font = fx.CreateMaterialIcons(15)
                    lbl.SetTextAlignment("BOTTOM","RIGHT")
                     iv.Text = Chr(0xE877)
                    lbl.TextColor=Main.xui.Color_DarkGray
                End If
            
                If Viewed = True Then
                    lbl.Font = fx.CreateMaterialIcons(15)
                    lbl.SetTextAlignment("BOTTOM","RIGHT")
                    iv.Text = Chr(0xE877)
                    lbl.TextColor=Main.xui.Color_RGB(88,199,243)
                
                    lbl.Font = fx.CreateMaterialIcons(15)
                    lbl.SetTextAlignment("BOTTOM","RIGHT")
                     iv.Text = Chr(0xE877)
                    lbl.TextColor=Main.xui.Color_RGB(88,199,243)
                End If
            End If
        End If
    Next
End Sub
 
Last edited:

mangojack

Well-Known Member
Licensed User
Longtime User
Firstly , I cannot duplicate your issue. The Material Icon appears with a single block of code.

1. Is the above code correct ? ... Is Label (lbl) in the CLV ? ... If not why do you Dim iv (ImageView ) ?
B4X:
Dim iv As B4XView=pnl.GetView(2)              
If Server = True Then
lbl.Font = fx.CreateMaterialIcons(15)
'etc  ..........


2. Use Icon Picker to access CHR() code ... Tools > Icon Picker
B4X:
iv.Text = Chr(0xE877)


3. Your above code could be shortened ... (note: iv / lbl)
B4X:
For x = 0 To CLV.Size-1
  Dim pnl As B4XView = CLV.GetPanel(x)
  If messagedts = CLV.GetValue(x)  Then
    If pnl.NumberOfViews >2 Then    '@@@ Neccessary ?
    Dim iv as B4XView pnl.GetView(2)
              
     If Server = True OR Delivered = True OR Viewed = True Then
      '@@@ where is lbl declared
       lbl.Font = fx.CreateMaterialIcons(15) 
       lbl.SetTextAlignment("BOTTOM","RIGHT")
       lbl.Text= Chr(0xE877)
       lbl.TextColor=Main.xui.Color_DarkGray                                  
     End If
   End if
End if
Next


There is a small possibility that even truncating the code might have an affect.

If the issue still remains , all I can suggest is uploading  a small sample project with  xCLV highlighting the issue.
 
Last edited:
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Inside the Custom list is a Pane with Multiple views.
First one is a Graphic
second one is the Date time Stamp
Third one is the one we are dealing with and is a Label in the initial layout with uses Material to display a tick or 2 ticks

So the Label is correct

B4X:
        p.AddView(ivBG, p.Width - bmpBG.Width * Main.xui.Scale, Gap, bmpBG.Width * Main.xui.Scale, bmpBG.Height * Main.xui.Scale)
        p.AddView(ivText, p.Width - Gap - ArrowWidth - TextWidth, 2 * Gap, TextWidth, TextHeight)
        p.AddView(ivtick, p.Width - Gap - ArrowWidth - TextWidth, 2 * Gap, TextWidth, TextHeight)
        p.Tag=messagedts



1611364702974.png

So while this screen is open, I need to change the Tick type and color of the Tick. I get a response from the server telling me that the message with the messagedts was delivered and then seen. When those messages arrive I update the local DB for future reload and also update on the screen if it is open. If it is not then it will update from the local DB as soon as it opens.

That field is a Label . If it was an image I would not be able to change it. Hope you understand what i am trying

I also updated the code with iv.Text = Chr(0xE876) and iv.Text = Chr(0xE877 as you suggested)
 
Last edited:
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
3. Your above code could be shortened ... (note: iv / lbl)
B4X:
For x = 0 To CLV.Size-1
  Dim pnl As B4XView = CLV.GetPanel(x)
  If messagedts = CLV.GetValue(x)  Then
    If pnl.NumberOfViews >2 Then    '@@@ Neccessary ?
    Dim iv as B4XView pnl.GetView(2)
            
     If Server = True OR Delivered = True OR Viewed = True Then
      '@@@ where is lbl declared
       lbl.Font = fx.CreateMaterialIcons(15)
       lbl.SetTextAlignment("BOTTOM","RIGHT")
       lbl.Text= Chr(0xE877)
       lbl.TextColor=Main.xui.Color_DarkGray                                
     End If
   End if
End if
Next


There is a small possibility that even truncating the code might have an affect.

If the issue still remains , all I can suggest is uploading  a small sample project with  xCLV highlighting the issue.

That code uses 2 different material Icons and has 2 different colors.
I cannot see how the shortened version will work for all of that. A possible reason why they do not appear is maybe i should try to add the MAGICAL sleep(50) in the mix.
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Initially it was IV but when I wanted to post it I changed to lbl so we did not get any confusion , I forgot to change that one
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
My mistake ... I was focusing on the Material Icon "icon" which all looked the same, but now see different color combinations.
The double code to make it work i can live with but I really need a solution for this

If there could be a command like clv.GetIndex(Value) would be perfect. If i could click the row in the list I would use CLV_ItemClick
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
To get the index, you could keep a list of the values in the order created (if you don't already have one) and do an indexof on that to get the position. The order of entries in the CLV won't change unless you change it.

Having to run the code twice should not be necessary, there must be something else wrong and if you don't fix it it will come back to bite you later.

How are you creating the panes on the clv in the first place? Is it in code or from a layout?

As I can't see the code, this is what I would check first:
Make sure you haven't got two lots of content in one pane.
If from a layout, make sure you haven't initialized the label again.
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
To get the index, you could keep a list of the values in the order created (if you don't already have one) and do an indexof on that to get the position. The order of entries in the CLV won't change unless you change it.

Having to run the code twice should not be necessary, there must be something else wrong and if you don't fix it it will come back to bite you later.

How are you creating the panes on the clv in the first place? Is it in code or from a layout?

As I can't see the code, this is what I would check first:
Make sure you haven't got two lots of content in one pane.
If from a layout, make sure you haven't initialized the label again.

Hi, Thank you for the advise, Just before I fell asleep I also thought about making the separate global list of the index number and the messagedts field when I create the pane for the CLV (or a global map with the key being the messagedts) . The Place where I get the problem of having the run the code twice is where I am overlaying the initial image with another view. This part is in code not from Designer.

in message #3 I have the code for making the panes. The last one is the one where I am adding the Material ICON

I also just thought of possibly the Z order is wrong so I am going to try pnl.BringToFront.

NO that did not help by changing the z-order
 
Last edited:
Upvote 0
Top