Edit Text Height

cnicolapc

Active Member
Licensed User
Longtime User
Hi,
You can now or in future have an implementation in EditText as in the attached that allows you to resize the height pressing enter?
Thank you in advance.
Nicola
 

Attachments

  • EditTextTest.apk
    9.5 KB · Views: 282

cnicolapc

Active Member
Licensed User
Longtime User
Hi, Erel
Screenshots here, every time I press enter in multiline Edittext control
automaticity you resize and move the rest down.
Useful option.
Thank you
Nicola
 

Attachments

  • shot_000002.jpg
    shot_000002.jpg
    4.7 KB · Views: 344
  • shot_000003.jpg
    shot_000003.jpg
    4.9 KB · Views: 310
  • shot_000005.jpg
    shot_000005.jpg
    5.5 KB · Views: 339
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can achieve this with the following code:
B4X:
Sub Process_Globals
   Dim su As StringUtils
End Sub

Sub Globals
   Dim EditText1 As EditText
   Dim Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub EditText1_EnterPressed
   SetEditTextHeight
End Sub
Sub EditText1_TextChanged (Old As String, New As String)
   If new.Length < old.Length Then SetEditTextHeight
End Sub
Sub SetEditTextHeight
   EditText1.Height = Max(60dip, 30dip + su.MeasureMultilineTextHeight(EditText1, EditText1.Text))
   Panel1.Top = EditText1.Top + EditText1.Height + 10dip
End Sub

The layout is made of an EditText named EditText1 and a Panel named Panel1. You can put other views on the Panel.
 
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
Hi Erel,
Your example I have been very useful. I was wrong to ask that the height of the 'EditText changed by pressing Enter. In fact, writing a long sentence the cursor moves to the under line but control not changed.
How can I get the same result? Taking into account different screen resolutions?
Nicola
 
Upvote 0
Top