Android Question Adding edittext to clv and measuring height problem

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Sub CreateListItem(Text As String) As Panel
    Dim txtHBbibleText As EditText
    txtHBbibleText.Initialize("txtHBBibleText")
'    txtHBbibleText.Gravity = Gravity.TOP
    txtHBbibleText.InputType = txtHBbibleText.INPUT_TYPE_NONE
    txtHBbibleText.SingleLine = False
    txtHBbibleText.TextSize = txtBibleSize
       
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 1dip, 1dip)
    p.AddView(txtHBbibleText, 0, 0, 1dip, 1dip)
    p.Color = xui.Color_White
   
    p.Top = 0
    p.Left = 0
    p.Width = 100%x
   
    txtHBbibleText.Top = 0
    txtHBbibleText.Left = 0
    txtHBbibleText.Width = 100%x
       
    txtHBbibleText.Text = Text
       
    Dim WhatHeight As Int
    Dim su As StringUtils
    WhatHeight = su.MeasureMultilineTextHeight(txtHBbibleText, txtHBbibleText.Text)
   
    p.Height = WhatHeight
    txtHBbibleText.Height = WhatHeight

    Return p
End Sub


I can't get the whole text to fit in the panel. Also, i have a gray divider line which i set to white color and size to 0. How do i fit the text properly and remove the divider line. Each verse is a panel.
 

Mahares

Expert
Licensed User
Longtime User
I can't get the whole text to fit in the panel.
Have you thought about using the clv.AddTextItem(...) method to fill the verses text. Each item will have one verse and regardless of the length of text, each xCLV item will have a different height to display all text without truncation. Something like this:
B4X:
Dim MyList As List
    MyList.Initialize
    MyList = Array ("Apple", "Banana", "Cherry", "Coconut", "Grapes", "Lemon", "Mango", "Melon", _
    "This is a long sentence that will be fully included in the xCLV since we are using the AddTextItem method", _
    "Orange", "Pear", "Pineapple", "Strawberry", "Litchi", "Watermelon", "Tomatoes", "Cherries", "Grapefruit" , _
    "Dates", "Berries", "Raisins", "Pomegranate" )
    MyList.SortCaseInsensitive(True)    
    For Each s As String In MyList        
        clv.AddTextItem(s, s)         
    Next
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
following on from @Mahares ... using AddTextItem .



Regarding the Divider line ... the attached image had the divider line set to 20 and color set to Transparent.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
I need the edit text and not the addtextitem which are labels. There are thing I can only do with edittext.
 
Upvote 0

Midimaster

Active Member
Licensed User
perhaps you will have a look on the sourcecode of CLVExpandable. This shows how to change the items height not by automatic, but by hand. At the moment I'm experimenting around with this and published some code her to exact this topic:

https://www.b4x.com/android/forum/t...vexpandable-and-clvdragger.123184/post-769846

I think this would work with EditTextViews too.

The related code is:
B4X:
Public Sub OpenItem(lbl As B4XView)
'drops down or closes the additional area of an item'
...

'class:CLVExpandable'
Private Sub ResizeItem (Index As Int, Collapse As Boolean)
    Dim item As CLVItem = mCLV.GetRawListItem(Index)
    Dim p As B4XView = item.Panel.GetView(0)
    If p.NumberOfViews = 0 Or (item.Value Is ExpandableItemData) = False Then Return
    Dim NewPanel As B4XView = xui.CreatePanel("")
    MoveItemBetweenPanels(p, NewPanel)
    Dim id As ExpandableItemData = item.Value
    id.Expanded = Not(Collapse)
    mCLV.sv.ScrollViewInnerPanel.AddView(NewPanel, 0, item.Offset, p.Width, id.ExpandedHeight)
    Dim NewSize As Int
    If Collapse Then NewSize = id.CollapsedHeight Else NewSize = id.ExpandedHeight
    mCLV.ResizeItem(Index, NewSize)
    NewPanel.SendToBack
    Sleep(mCLV.AnimationDuration)
    If p.Parent.IsInitialized Then
        MoveItemBetweenPanels(NewPanel, p)
    End If
    NewPanel.RemoveViewFromParent
End Sub


Private Sub MoveItemBetweenPanels (Src As B4XView, Target As B4XView)
    Do While Src.NumberOfViews > 0
        Dim v As B4XView = Src.GetView(0)
        v.RemoveViewFromParent
        Target.AddView(v, v.Left, v.Top, v.Width, v.Height)
    Loop
End Sub


Public Sub OpenItem(lbl As B4XView)
    Dim index As Int=mCLV.GetItemFromView(lbl)
    Dim data As ExpandableItemData = mCLV.GetValue(index)
    ResizeItem(index,data.Expanded)
End Sub


Public Sub

Here the item's height changes to a fixed second height when I press a button. But you could change the code to a any height, depending on the EditTextView's needs.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…