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

Discussion in 'Android Questions' started by asales, Jul 23, 2019.

  1. asales

    asales 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.
  2. DonManfred

    DonManfred Expert Licensed User

  3. emexes

    emexes Well-Known Member 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)

    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: Jul 23, 2019
  4. asales

    asales 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 StringAs Panel
    Dim p As B4XView = xui.CreatePanel("")
    "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

    001dip, TextWidth + 10dip36dip)
       p1.Width = TextWidth + 
    Return p
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice