CustomListView is a versatile view that covers the basic requirements for lists with many variants.
Even the dynamic height adjustment of the items is possible, but then the focus of the item is lost.
In the attached small testproject every clv item contains a layout with an edittext on it.
The aim is to enlarge the edittext and its parent-panel while the user enters more words. This is realized and works as usual via "MeasureMultilineTextHeight".
The problem is that the current clv-item loses focus as soon as the function".ResizeItem" is called.
JumpToItem was tried out, but led to an optical jumping back and forth, which is not conducive to a positive user experience.
Does anyone have a solution how to execute a "ResizeItem" on the xCustomListview, so that the focus remains on the active EditText (including cursor position)?
Even the dynamic height adjustment of the items is possible, but then the focus of the item is lost.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
CustomListView1.Add( CreateListItemFlEditText("testtext 1. Some longer Text aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmmmmmm nn oooo ppppp qqqqqqq.", "hinttext1", CustomListView1.AsView.Width, 20dip), -111)
CustomListView1.Add( CreateListItemFlEditText("testtext 2. A little longer than the text before.", "hinttext2", CustomListView1.AsView.Width, 20dip), -222)
CustomListView1.Add( CreateListItemFlEditText("testtext 3. Short.", "hinttext3", CustomListView1.AsView.Width, 20dip), -333)
CustomListView1.Add( CreateListItemFlEditText("testtext 4. This Text is longer to force another height of the edittext.", "hinttext4", CustomListView1.AsView.Width, 20dip), -444)
bolReadyForInput = True
End Sub
Sub CreateListItemFlEditText(Text As String, Text2 As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
p.SetLayout(0, 0, Width, Height)
'
p.LoadLayout("editfloatmic")
lblEdtFloatMic.TextColor = Starter.intColorAccent
'
Dim intH As Int = Starter.su.MeasureMultilineTextHeight(lblEdtFloatMeasureInvis, Text) +48dip
Dim intHPan As Int = intH + 8dip
panEdtFloatMic.Height = intH
'
edtFloatMic.Height = intH
edtFloatMic.Text = Text
edtFloatMic.EditText.HintColor = Starter.colorBlack38
edtFloatMic.EditText.TextColor = Starter.colorBlack87
edtFloatMic.Hint = Text2
edtFloatMic.EditText.SingleLine = False
edtFloatMic.EditText.Gravity = Bit.Or(Gravity.TOP, Gravity.LEFT)
'
p.SetLayout(0, 0, Width, intHPan)
'
lblEdtFloatMic.Text = ""
Return p
End Sub
Sub edtFloatMic_TextChanged (Old As String, New As String)
If Not(bolReadyForInput) Then Return
Dim index As Int = CustomListView1.GetItemFromView(Sender)
Dim b4xpnl As B4XView = CustomListView1.GetPanel(index)
Dim b4xedtText As B4XView = b4xpnl.GetView(0)
Dim b4xlblEdtFloatMeasureInvis As B4XView = b4xpnl.GetView(0)
Dim intH As Int = Starter.su.MeasureMultilineTextHeight(b4xlblEdtFloatMeasureInvis, New) +48dip
If intH = b4xedtText.Height Then Return
' --- --- --- --- --- --- --- --- --- ---
' New height is needed
' --- --- --- --- --- --- --- --- --- ---
Dim intHPan As Int = intH +8dip
b4xedtText.Height = intH
'
Dim panEdtFrame As B4XView= b4xpnl.GetView(1)
panEdtFrame.Height = intH
CustomListView1.ResizeItem(index, intHPan)
'CustomListView1.JumpToItem(index )
'b4xedtText.RequestFocus
'b4xedtText. ( ...somehow set cursor to end of text ... )
End Sub
In the attached small testproject every clv item contains a layout with an edittext on it.
The aim is to enlarge the edittext and its parent-panel while the user enters more words. This is realized and works as usual via "MeasureMultilineTextHeight".
The problem is that the current clv-item loses focus as soon as the function".ResizeItem" is called.
Example: As you can see here, a word is inserted at position (1) and the height is readjusted.
Afterwards, however, the focus changes to the top item at position (2).
Afterwards, however, the focus changes to the top item at position (2).
Does anyone have a solution how to execute a "ResizeItem" on the xCustomListview, so that the focus remains on the active EditText (including cursor position)?