Android Question [Solved] Horizontal customlistview with different text width in the item


Well-Known Member
Licensed User
I tried to recreated this code from Erel to a horizontal list with texts in different widths, without success:

I have a fixed list with some texts with differents sizes, like this:
US Dollar
Argentine Peso
Australian Dollar
Brazilian Real

I don't need search or highlight in the text, only display this texts in a rounded panel that fit the width of the text:

Thanks in advance for any help.


Licensed User
edit: in retrospect, doing it this way will likely end up being more complicated than using an already-scrollable control... but I'll leave the post here just in case it prompts ideas applicable to similar use cases (never hurts to have an extra spanner choice in the programming toolbox)

... fixed list with some texts with differents sizes
... need ... only display this texts in a rounded panel that fit the width of the text
If the list is small(ish) and fixed, then it might be quicker to just whip it up hardwired in Designer using labels with rounded corners, on a single panel so that you can move/scroll the entire block left and right as a single entity, eg:


Last edited:
Upvote 0


Well-Known Member
Licensed User
The texts of the list are fixed, but they can change places.

Almost there with this code:
For i = 0 To li.Size - 1
   Dim item As String = li.Get(i)
   CLV1.Add(CreateItem(item), i)

Private Sub CreateItem(Text As String) As Panel
   Dim p As B4XView = xui.CreatePanel("")
   p.SetLayoutAnimated(0, 0, 0, 100dip, 36dip)
   p.LoadLayout("cell")  'a panel with a label inside
   Dim p1 As Panel = p.GetView(0)
   Dim lb As Label = p1.GetView(0)

   Dim xlbl As B4XView = lb
   fnt = xlbl.Font

   lb.Text = Text

   Dim TextWidth As Int = MeasurementCanvas.MeasureText(Text, fnt).Width

   p.SetLayoutAnimated(0, 0, 1dip, TextWidth + 10dip, 36dip)
   p1.Width = TextWidth + 8dip
   Return p
End Sub
Upvote 0