B4J Question [ABMaterial] Image Only ComboBox

Cableguy

Expert
Licensed User
Longtime User
Hi Gurus

I know that ABMCombo supports adding images to the items but the selected item shows only the text property...
Is it possible to set the selected item to show its image?
Like in the demo example, when selecting "Dad", which in its item has a small picture, instead of getting just the Selected item "Dad" text, we would get also the image
 

Harris

Expert
Licensed User
Longtime User
This is how I build a combo with images...
The images are stored in a folder and loaded into each item, along with the name.
I use the returnID (the image file name) and store that to a table as the selected image.

B4X:
' create combo
    Dim lst As List
    lst.Initialize
    lst = File.ListFiles( File.DirApp&"/www/muniman/images/pics")

    Dim ABMGentiInsp_Typeimg As ABMCombo
    ABMGentiInsp_Typeimg.Initialize(page, "ABMGentiInsp_TypeTSpare1", "Select a Unit Image", 320, "")
    ABMGentiInsp_Typeimg.IconName = "mdi-image-collections"
    For i = 0 To lst.Size - 1
      Dim st As String = lst.Get(i)
      If  st.Contains(".jpg") Then   
          ABMGentiInsp_Typeimg.AddItem( ""&lst.Get(i), ""&lst.Get(i), BuildItem("S"&i,  "../images/pics/"&lst.Get(i),  "Image Class", ""&lst.Get(i)))
      End If     
    Next 
    ABMGentiInsp_TypeModal.Content.CellR(1,1).AddComponent(ABMGentiInsp_Typeimg)

The BuildItem sub...

B4X:
Sub BuildItem(id As String, image As String, Title As String, Subtitle As String) As ABMContainer
    Dim ItemCont As ABMContainer
    ItemCont.Initialize(page, id, "")   
    ItemCont.AddRowsM(1,False,6,0, "").AddCellsOSMP(1,0,0,0,3,2,2,0,0,16,0,"").AddCellsOS(1,0,0,0,9,10,10,"")
    ItemCont.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
   
    Dim SubItemCont As ABMContainer
    SubItemCont.Initialize(page, id & "SubItemCont", "")   
    SubItemCont.AddRowsM(1,False,  0,0,"").AddCells12MP(1, -6,0,140,0,"").AddCells12MP(1, 0,0,140,0,"")
    SubItemCont.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
   
    ItemCont.Cell(1,2).AddComponent(SubItemCont)
   
    Dim img As ABMImage
    img.Initialize(page, id & "img", image, 1)
    img.SetFixedSize(120,75)
'    img.IsCircular = True
    img.IsResponsive = False
   
    ItemCont.Cell(1,1).AddComponent(img)
   
    Dim lbl1 As ABMLabel
    lbl1.Initialize(page, id & "lbl1", Title, ABM.SIZE_H6, False, "lightblue")
    lbl1.VerticalAlign = True
   
    SubItemCont.Cell(1,1).AddComponent(lbl1)
   
    Dim lbl2 As ABMLabel
    lbl2.Initialize(page, id & "lbl2", Subtitle, ABM.SIZE_H6, False, "")
    lbl2.VerticalAlign = True
   
    SubItemCont.Cell(1,2).AddComponent(lbl2)
   
    Return ItemCont
End Sub
 
Upvote 0
Top