Android Question Changing floattextfield's height with the IME_HeightChanged.

Hanz

Active Member
I came across a chat example by Erel. It shows how to create bubble color. But it does not show how to change the floattextfield's height as the number of letters increases or when the enter key is pressed. I also found this forum:
B4X:
https://www.b4x.com/android/forum/threads/whats-the-correct-way-to-resize-a-b4xfloattextfield.131956/#content
Any further guidance how to increase the height of floattextfield's height as the user type letters just like in the FB messenger? I followed erel's chat example. The floattextfield is inside the panel. I guest I have to increase the panel's height as well.

Thanks.
 

Omar Parra A.

Expert
Licensed User
Longtime User
I came across a chat example by Erel. It shows how to create bubble color. But it does not show how to change the floattextfield's height as the number of letters increases or when the enter key is pressed. I also found this forum:
B4X:
https://www.b4x.com/android/forum/threads/whats-the-correct-way-to-resize-a-b4xfloattextfield.131956/#content
Any further guidance how to increase the height of floattextfield's height as the user type letters just like in the FB messenger? I followed erel's chat example. The floattextfield is inside the panel. I guest I have to increase the panel's height as well.

Thanks.
not tested
B4X:
Sub B4XFloatTextField1_HeightChanged (NewHeight As Int, OldHeight As Int)
    Dim difference As Int = OldHeight - NewHeight
    B4XFloatTextField1.Base_Resize(B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height - difference)
End Sub
 
Upvote 0

Hanz

Active Member
not tested
B4X:
Sub B4XFloatTextField1_HeightChanged (NewHeight As Int, OldHeight As Int)
    Dim difference As Int = OldHeight - NewHeight
    B4XFloatTextField1.Base_Resize(B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height - difference)
End Sub
Thanks, and looking at the code, how about the panel where the b4xfloattextfield is in? The panel has to increase its height too right?
 
Upvote 0

Omar Parra A.

Expert
Licensed User
Longtime User
not tested
B4X:
Sub B4XFloatTextField1_HeightChanged (NewHeight As Int, OldHeight As Int)
    Dim difference As Int = OldHeight - NewHeight
    B4XFloatTextField1.mBase.Height = B4XFloatTextField1.mBase.Height - difference
    B4XFloatTextField1.Base_Resize(B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height)
End Sub
 
Upvote 0

Hanz

Active Member
not tested
B4X:
Sub B4XFloatTextField1_HeightChanged (NewHeight As Int, OldHeight As Int)
    Dim difference As Int = OldHeight - NewHeight
    B4XFloatTextField1.mBase.Height = B4XFloatTextField1.mBase.Height - difference
    B4XFloatTextField1.Base_Resize(B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height)
End Sub
I'm not sure, does B4XFloatTextField has HeightChanged method? Even the B4XFloatTextField has no Base_Reside method? I think the latter is called thru "callsub3".
 
Upvote 0

Hanz

Active Member
There is no HeightChanged event because the height will never change unless you change it.
You can handle the TextChanged event and measure the string height with StringUtils.MeasureMultilineText.
I'm having a warning with either of these codes:
B4X:
Dim su As StringUtils
Dim h As Int = su.MeasureMultilineTextHeight(txtSendMessage, txtSendMessage.Text)
B4X:
Dim su As StringUtils
txtSendMessage.TextField.Height = su.MeasureMultilineTextHeight(txtSendMessage, txtSendMessage.Text)
The warning says, "types do not match."
 
Upvote 0

Omar Parra A.

Expert
Licensed User
Longtime User
?
B4X:
Private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
   
    Dim SU As StringUtils
    Dim TextHeight As Int = SU.MeasureMultilineTextHeight(B4XFloatTextField1.TextField.As(EditText), B4XFloatTextField1.Text)
    Dim HintHeight As Int = SU.MeasureMultilineTextHeight(B4XFloatTextField1.TextField.As(EditText), B4XFloatTextField1.HintText)
    B4XFloatTextField1.mBase.Height = TextHeight + HintHeight
    CallSub3(B4XFloatTextField1, "Base_Resize", B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height)

End Sub

1631932296711.png
 

Attachments

  • 1.gif
    1.gif
    100.3 KB · Views: 65
Upvote 0

Hanz

Active Member
?
B4X:
Private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
 
    Dim SU As StringUtils
    Dim TextHeight As Int = SU.MeasureMultilineTextHeight(B4XFloatTextField1.TextField.As(EditText), B4XFloatTextField1.Text)
    Dim HintHeight As Int = SU.MeasureMultilineTextHeight(B4XFloatTextField1.TextField.As(EditText), B4XFloatTextField1.HintText)
    B4XFloatTextField1.mBase.Height = TextHeight + HintHeight
    CallSub3(B4XFloatTextField1, "Base_Resize", B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height)

End Sub

View attachment 119233
Thanks, it truly expands but, it expands towards below. I can't no longer see it because the keyboard covers it. How can I make it expand towards up? The textfiled is at the bottom and I wish to expand it from the bottom to the top just like in the FB messenger or phone's text messages.
 
Upvote 0

Hanz

Active Member
?
B4X:
Private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
  
    Dim SU As StringUtils
    Dim TextHeight As Int = SU.MeasureMultilineTextHeight(B4XFloatTextField1.TextField.As(EditText), B4XFloatTextField1.Text)
    Dim HintHeight As Int = SU.MeasureMultilineTextHeight(B4XFloatTextField1.TextField.As(EditText), B4XFloatTextField1.HintText)
    B4XFloatTextField1.mBase.Height = TextHeight + HintHeight
    CallSub3(B4XFloatTextField1, "Base_Resize", B4XFloatTextField1.mBase.Width, B4XFloatTextField1.mBase.Height)

End Sub

View attachment 119233
I added this code at the end of your code:
B4X:
pnlBottomMessage.Height = txtSendMessage.mBase.Height
It helps but the exact increase is not accurate, and I have to pressed the phone's "back button" to remove the keyboard, then once the keyboard disappears, what is left is the textfield and it will show the entire textfield. LOL! I don't know what's going, I feel like a kid breaking everything.
 
Upvote 0
Top