Resizing listview's individual item height according to their content

Discussion in 'Android Questions' started by walterf25, May 18, 2013.

  1. walterf25

    walterf25 Well-Known Member Licensed User

    Hello All, I need to find a solution to my problem, I'm working with an app requires a listview.
    I need to set the itemheight of each item according to the text, sometimes I will have a short string and others i will have a long string, so i need to resize the item height accordingly.
    I've tried Erel's Custom Listivew and it works great, but it has some issues and i don't have the time to figure out how to fix them, is there a way to use the listview that comes with the core library, and be able to change the itemheight as well.

    Thanks All
  2. Harris

    Harris Well-Known Member Licensed User

    Listviews work wonderfully with short text.
    I have fooled around with measuring the text length and trying to adjust the height with varying results - most unsatisfactory.

    So now I just set the height to my expected max. Short text leaves alot of white space, long fills the view nicely (example below).

    You could always purchase the UtimateListView from Informatix: It likely handles this and SO MUCH more...

    *** It just made Senior status with this post - but I am only 55 this coming June... (and don't see the "freedom" in it)

    Sub Activity_Create(FirstTime As Boolean)
       LV1.ScrollingBackgroundColor = 
    Colors.Transparent ' need this to avoid the ugly black background when scrolling
       Dim lb, lbl1,lbl As Label

       lb = LV1.SingleLineLayout.Label
        lb.Color = 
        lb.TextColor = 
        LV1.SingleLineLayout.ItemHeight = 
    30dip ' small height group label
       lbl = LV1.TwoLinesAndBitmap.Label
       lbl.TextColor = 
       lbl1 = LV1.TwoLinesAndBitmap.SecondLabel

        LV1.TwoLinesAndBitmap.SecondLabel.Width  = LV1.Width - 
    ' the above line prevents the text displaying out of view.  Allows text to wrap within the view   

    lbl1.TextColor = 

    If DefCM.GetDevicePhysicalSize < 6 Then    ' if phone
           LV1.TwoLinesAndBitmap.ItemHeight = 70dip ' set item height and text size
          lbl.TextSize = 18
          lbl1.TextSize = 

    Else  ' if tablet
           LV1.TwoLinesAndBitmap.ItemHeight = 80dip
          lbl.TextSize = 
          lbl1.TextSize = 
    End If
    End Sub
    Last edited: May 18, 2013
  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