Android Question Change Textbox Height on second Row

Alexander Stolte

Expert
Licensed User
Longtime User
Hey guys, i have a question, I would like give the textbox a dynamic height
like this:

I fail because the textbox then always disappears down.
has anyone ever done this?

this is my code:

B4X:
Sub IndexOfNth(s As String, SearchFor As String, Count As Int) As Int
    Dim res As Int = -1
    For i = 0 To Count - 1
        res = s.IndexOf2(SearchFor, res + 1)
        If res = -1 Then Return -1
    Next
    Return res
End Sub

Sub txb_content_TextChanged (Old As String, New As String)
    Dim hoehe As Object
    hoehe = su.MeasureMultilineTextHeight(txb_content,txb_content.Text )
  


  
    Dim i As Int = IndexOfNth(txb_content.text, CRLF, 5)
    If i < 1 Then
        txb_content.Height = hoehe + 20dip
        pnl_ground.Height = hoehe + 20dip
        'pnl_ground.Top = pnltop + 20dip
      
      
  
      
      
        Else If i < 2 And i > 1 Then
        txb_content.Height = hoehe + 20dip
        pnl_ground.Height = hoehe + 20dip
        'pnl_ground.Top = pnltop + 40dip

      
    Else If i < 3 And i > 2 Then
        txb_content.Height = hoehe + 20dip
        pnl_ground.Height = hoehe + 20dip
    '    pnl_ground.Top = pnltop + 60dip

    Else If i < 4 And i > 3 Then
        txb_content.Height = hoehe + 20dip
        pnl_ground.Height = hoehe + 20dip
    '    pnl_ground.Top = pnltop + 80dip
    Else If i < 5 And i > 4 Then
        txb_content.Height = hoehe + 20dip
        pnl_ground.Height = hoehe + 20dip
        'pnl_ground.Top = pnltop + 100dip
    End If
End Sub
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
But the IME Lib. is not this what i need.

B4X:
Sub Globals
   Dim imeglobal As IME
   Private pnl_ground As Panel
   Dim pnltop As Object
   Dim pnl_ground as Panel
    Dim su As StringUtils
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frm_contentdetail")
 
    imeglobal.Initialize("imeglobal")
    imeglobal.AddHeightChangedEvent
End Sub

Sub imeglobal_HeightChanged (NewHeight As Int, OldHeight As Int)
    pnltop = NewHeight
    pnl_ground.Top = NewHeight - pnl_ground.Height
End Sub

Sub txb_content_TextChanged (Old As String, New As String)
    Dim hoehe As Int
    hoehe = su.MeasureMultilineTextHeight(txb_content,txb_content.Text )
  


  
    Dim i As Int = IndexOfNth(txb_content.text, CRLF, 5)
    If i < 1 Then
        txb_content.Height = su.MeasureMultilineTextHeight(txb_content,txb_content.Text ) +20dip
    '    pnl_ground.Height = su.MeasureMultilineTextHeight(txb_content,txb_content.Text ) +20dip
        pnl_ground.Top = pnltop - pnl_ground.Height
  
        ToastMessageShow(pnltop, True)
        'pnl_ground.Top = hoehe - pnl_ground.Height
        'txb_content.Height = pnl_ground.Top - txb_content.Top
      
      
        Else If i < 2 And i > 1 Then
        'txb_content.Height = hoehe + 20dip
    '    pnl_ground.Height = hoehe + 20dip
  
        txb_content.Height = su.MeasureMultilineTextHeight(txb_content,txb_content.Text ) +20dip
        pnltop = pnltop +40
        pnl_ground.Top = pnltop  - pnl_ground.Height
        'pnl_ground.Height = su.MeasureMultilineTextHeight(txb_content,txb_content.Text ) +20dip
        ToastMessageShow(pnltop, True)
        'pnl_ground.Top = pnltop +20dip
        'pnl_ground.Top = hoehe - pnl_ground.Height
    '    txb_content.Height = pnl_ground.Top - txb_content.Top
    Else If i < 3 And i > 2 Then
        'txb_content.Height = hoehe + 20dip
        'pnl_ground.Height = hoehe + 20dip
      
        txb_content.Height = su.MeasureMultilineTextHeight(txb_content,txb_content.Text ) +20dip
        'pnl_ground.Height = su.MeasureMultilineTextHeight(txb_content,txb_content.Text ) +20dip
      
        'pnl_ground.Top = pnltop
        'pnl_ground.Top = hoehe - pnl_ground.Height
        'txb_content.Height = pnl_ground.Top - txb_content.Top

    End If
End Sub

My Problem is, that the "imeglobal_HeightChanged" is only triggered when I open the keyboard again and that is not the Sense of the matter.

I change the height of the edittext and of his panel, then I need the new top value somehow.

The goal is to be able to go 6 columns down and then automatically move it upwards, as with WhatsApp.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…