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
    Walter
     
  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...
    http://www.basic4ppc.com/forum/addi...es/22736-lib-chargeable-ultimatelistview.html

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

    Code:
    Sub Activity_Create(FirstTime As Boolean)
     
       
    Activity.LoadLayout("SetAll")
       
       Panel1.SetLayout(
    00100%x100%y)
       LV1.SetLayout(
    00100%x100%y)
       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 = 
    Colors.ARGB(140,90,90,120)
        lb.TextColor = 
    Colors.ARGB(240,180,180,20)
        LV1.SingleLineLayout.ItemHeight = 
    30dip ' small height group label
       
       lbl = LV1.TwoLinesAndBitmap.Label
       lbl.TextColor = 
    Colors.White
       
       
       lbl1 = LV1.TwoLinesAndBitmap.SecondLabel

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

    lbl1.TextColor = 
    Colors.ARGB(240,190,180,0)

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

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