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:
    https://www.b4x.com/android/forum/threads/b4x-xui-minisearchview-autocomplete-field.93564/

    I have a fixed list with some texts with differents sizes, like this:
    Code:
    US Dollar
    Argentine Peso
    Australian Dollar
    Boliviano
    Brazilian Real
    Euro
    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:
    clv_hor1.jpg

    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:

    upload_2019-7-23_15-52-43.png

    upload_2019-7-23_15-49-57.png
     
    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:
    Code:
    For i = 0 To li.Size - 1
       
    Dim item As String = li.Get(i)
       CLV1.Add(CreateItem(item), i)
    Next

    Private Sub CreateItem(Text As StringAs Panel
       
    Dim p As B4XView = xui.CreatePanel("")
       p.SetLayoutAnimated(
    000100dip36dip)
       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(
    001dip, TextWidth + 10dip36dip)
       p1.Width = TextWidth + 
    8dip
       
       
    Return p
    End Sub
     
Loading...
  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