Android Question What is best way for pictures in combobox

MarcRB

Active Member
Licensed User
Longtime User
What is the best view for creating a spinner / combobox with pictures (icons) and text?

Something like this C# example
 

Mahares

Expert
Licensed User
Longtime User
combobox with pictures (icons) and text?
You can use CSBuilder with text and material Icons as an example:
B4X:
lstItems.AddAll(Array As String("Dog", "Cat", "Bird", "Camel", "Tiger", "Elephant"))
    Dim f(3) As Int =Array As Int( (0xE195), (0xE531),(0xE530))
    Dim cs As CSBuilder
    For i = 0 To lstItems.Size -1
        B4XComboBox1.cmbBox.AddAll(Array(cs.Initialize.size(34).Typeface(Typeface.MATERIALICONS).VerticalAlign(5dip).Append(Chr(f(Rnd(0,3)))). _
        pop.Pop.append(TAB).Append(lstItems.Get(i)).PopAll))
    Next
1647025137146.png

B4X:
 
Upvote 0

MarcRB

Active Member
Licensed User
Longtime User
This is great, but images would be better for my project.
If someone have a good idea...
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
You can use CSBuilder to incorporate images:
Sample CSBuilder Image:
Dim cs As CSBuilder
cs.Initialize.Size(30).Typeface(Typeface.MONOSPACE)
cs.Append("B4A: ").Image(LoadBitmap(File.DirAssets, "b4a.png"), 40dip, 40dip, False).Append(CRLF)
cs.Append("B4i: ").Image(LoadBitmap(File.DirAssets, "b4i.png"), 40dip, 40dip, False).Append(CRLF)
cs.Append("B4J: ").Image(LoadBitmap(File.DirAssets, "b4j.png"), 40dip, 40dip, False).Append(CRLF)
cs.Append("B4R: ").Image(LoadBitmap(File.DirAssets, "b4r.png"), 40dip, 40dip, False).Append(CRLF)
cs.PopAll
Label1.Text = cs
Activity.Title = cs
See https://www.b4x.com/android/forum/threads/charsequence-csbuilder-tutorial.76226/#content
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
images would be better for my project.
Post #4 showed you how to add an image to a label via CSBuilder. This example shows you how to apply images to a B4XComboBox via a CSBuilder:
B4X:
Dim MyList  As List
    MyList.initialize
    MyList.AddAll(Array("ukraine.png", "romania.png", "poland.png", "moldova.png"))
    lstItems.AddAll(Array As String("Dog", "Cat", "Bird", "Camel", "Tiger", "Elephant"))
    Dim cs As CSBuilder
    For i = 0 To lstItems.Size -1
        B4XComboBox1.cmbBox.AddAll(Array(cs.Initialize.Image(LoadBitmap(File.DirAssets, MyList.Get(Rnd(0,4))), 60dip, 40dip, False). _
        append(TAB).append(TAB).size(38).Append(lstItems.Get(i)).PopAll))
    Next
1647048370105.png
 
Upvote 0
Top