Android Question xCustomListView resize to fit content

Status
Not open for further replies.

cliv

Member
Licensed User
Longtime User
I use this for load item:
B4X:
Private Sub CreateItem (Width As Int,PubDate As String, Title As String, Content As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 280dip
 
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("Card1")

    lblPubDate.Text = PubDate
    lblTitle.Text = Title
    lblContent.Text = Content
 
    Dim newHeight As Int
    newHeight=su.MeasureMultilineTextHeight(lblContent, lblContent.Text)
    '???? Resize Panel height and lblContent height
 
    Return p
End Sub

... How can i resize PANEL and lblContent to fit text added when this is very long...?
... su is StringUtils
 

DonManfred

Expert
Licensed User
Longtime User
Check the Class code... Look at AddTextitem and how it works.
 
Last edited:
Upvote 0

cliv

Member
Licensed User
Longtime User
... Look at AddTextitem and how it works.
This is a card list and items layout are created with the designer,
based on sample Cards list with CustomListView:
https://www.b4x.com/android/forum/threads/cards-list-with-customlistview.87720/


... so now i use this code:

B4X:
Private Sub CreateItem (Width As Int,PubDate As String, Title As String, Content As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 280dip
 
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)

    Dim dummyLabel As Label
    dummyLabel.Initialize("")
    p.AddView(dummyLabel, 0, 0, Width-30dip, 0)
    Activity.AddView(p, 0, 0, Width, Max(height, su.MeasureMultilineTextHeight(dummyLabel, Content)))
    p.LoadLayout("Card1")
 
    lblContent.Text = Content
    dummyLabel.RemoveView
    p.RemoveViewFromParent
    lblPubDate.Text = PubDate
    lblTitle.Text = Title
 
    Return p
End Sub
 
Last edited:
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
This is a card list and items layout are created with the designer,
based on sample Cards list with CustomListView:
https://www.b4x.com/android/forum/threads/cards-list-with-customlistview.87720/


... so now i use this code:

B4X:
Private Sub CreateItem (Width As Int,PubDate As String, Title As String, Content As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 280dip

    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)

    Dim dummyLabel As Label
    dummyLabel.Initialize("")
    p.AddView(dummyLabel, 0, 0, Width-30dip, 0)
    Activity.AddView(p, 0, 0, Width, Max(height, su.MeasureMultilineTextHeight(dummyLabel, Content)))
    p.LoadLayout("Card1")

    lblContent.Text = Content
    dummyLabel.RemoveView
    p.RemoveViewFromParent
    lblPubDate.Text = PubDate
    lblTitle.Text = Title

    Return p
End Sub


This code does not work
 
Upvote 0
Status
Not open for further replies.
Top