Android Question change an image on a custom list view panel

giggetto71

Active Member
Licensed User
Longtime User
Hi,
I have an app where I a custom list view made with custom panels (cards) made with few labels and a couple of images.
I need to change at run time the cards on cards click event and I can do that without problems leveraging the Tag properties of the view for the labels.

B4X:
        Dim pnl As B4XView = CLV1.GetPanel(ClickedAlertCard)
       For Each v As View In pnl.GetAllViewsRecursive
          If v Is Label Then
             Dim lbl As Label = v           
             Select lbl.Tag
                Case "TopicLbl"
                   lbl.Text = edtAlertTopic.Text
                Case "PayloadLbl"
                                        
                    If AlertElement.AlertType = 0 Then
                       lbl.Text =  "=" &  edtAlertValue.Text
                    Else
                       lbl.Text =  AlertElement.AlertOper &  edtAlertValue.Text   
                    End If
                        
             End Select               
          End If
          If v Is B4XView Then
                Dim img As B4XView = v
              Select img.Tag
                 Case "StatusImg"
                    
                    img.SetBitmap(xui.LoadBitmapResize(File.DirAssets,TempImgStr,img.Width,img.Height,True))
                    
              End Select
          End If
       Next


for some reasons I cannot change the image using the setbitmap method which works just fine when I use it to set the image when I create the cards using:

B4X:
Private Sub CreateItem2(Width As Int, Title As String, Image As String, Content As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 125dip
    Dim ss As StringFunctions,TempList As List
    ss.Initialize
    TempList = ss.Split(Content,",")
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 300dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("Alert")
        
    lblAlertCardTitle.text =Title
    lblAlertCardTopic.Text =  TempList.Get(0)
    If TempList.Get(2) = "0" Then 'boolean
       lblAlertCardPayload.Text = " = " & TempList.Get(1)
    Else
       lblAlertCardPayload.Text = TempList.Get(3) & " " &  TempList.Get(1)   
    End If
    
    imgAlertType.SetBitmap(xui.LoadBitmapResize(File.DirAssets,Image,imgAlertType.Width,imgAlertType.Height,True))
    Return p
End Sub

Any idea why the SetBitmap does not seem to load the image ?
thanks!
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Are you sure the setbitmap line is getting executed? Try changing the if above it:
B4X:
If v Is ImageView Then
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Maybe something like this @giggetto71
B4X:
Sub xCLV_ItemClick (Index As Int, Value As Object)
    Dim PnlView As B4XView = xCLV.GetPanel(Index).GetView(0)
    Dim Img As B4XView = PnlView.GetView(8) '8 is the ImageView, depends on your layout
        Img.SetBitmap(LoadBitmapResize(File.DirAssets, <<BITMAP IMAGE TO LOAD>>), Img.Width, Img.Height, True))
End Sub
 
Last edited:
Upvote 0
Top