Android Question Can the customlistview automatically adjust its height and width based on the content inside

Makumbi

Well-Known Member
Licensed User
B4X:
    Activity.LoadLayout("LoadChats")

    Dim rs As ResultSet = Starter.oSQL.ExecQuery("SELECT Timestamp, Account, Names,Sms FROM tbl_Messagesdata")
        
    Do While rs.NextRow
        Dim sms As String
        Dim Accountk As String
        Dim Namesk As String
        sms=rs.GetString("Sms")
        Accountk=rs.GetString("Account")
       Namesk=rs.GetString("Names")
    
        CLV1.Add(CreateItem(CLV1.AsView.Width, sms,Accountk,Namesk), "")

    Loop
    rs.Close
    
End Sub



Private Sub CreateItem(Width As Int, Content As String,Accountk As String,Namesk As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 200dip
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 350dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("CardChats")
    Account.Text = Accountk
    Names.Text = Namesk
    lblContent.Text = Content
    
    Return p
End Sub
 

Attachments

  • Screenshot_1588059355.png
    Screenshot_1588059355.png
    21.4 KB · Views: 191

Makumbi

Well-Known Member
Licensed User
CLV doesn't know anything about the items content.

The only exception is with AddTextItem where CLV matches the height to the text content.

You can use StringUtils.MeasureMultilineString to calculate the height yourself.
Please Erel any small example in relation to this particular aspect will be very helpful because i have search but i cant figure out how this is going to happen thanks
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Please Erel any small example in relation to this particular aspect will be very helpful because i have search but i cant figure out how this is going to happen thanks


Think back a fortnight when you were trying to store / retrieve Chat Messages using SQL.


You were studying an example by @Douglas Farias ,,, https://www.b4x.com/android/forum/t...xample-adjustable-text-size.87063/post-552101

Look at : Sub Add_Conversation especially the section commented ... "HERE WE GET THE MESSAGE AND NAME CHAT" (size)

The author uses StringUtils.MeasureMultilineString to calculate the height of the chat labels , then adjusting the CLV panel height to suit.
 
Last edited:
Upvote 0
Top