Android Question [B4A] Scrolls editable text of B4XFloatFieldText in PreferenceDialog()

T201016

Active Member
Licensed User
Longtime User
Hello,
I cannot get the vertical scroll action in the edited (see: Description) field.
Actually, I can only scroll the whole dialogue view: PrefDialog.

I have included a short source:
SetFloatTextField:
Private Sub SetFloatTextField(FloatTextField As B4XFloatTextField, SmallLabelTextSize As Int, LargeLabelTextSize As Int,TextSize As Int, SmallLabelGravityLeft As Int)
    FloatTextField.SmallLabelTextSize = SmallLabelTextSize 'Hint Small
    FloatTextField.LargeLabelTextSize = LargeLabelTextSize 'Hint Large
    FloatTextField.TextField.TextSize = TextSize 'Text
 
    Dim TextFont As B4XFont = xui.CreateFont2(FloatTextField.HintFont, FloatTextField.SmallLabelTextSize)
    Dim TextWidth As Int = MeasureTextWidth(FloatTextField.HintText, TextFont)
    Dim BorderRadius As Int = 0

    FloatTextField.HintLabelSmallOffsetY = 3 'Inside

    If SmallLabelGravityLeft = Gravity.RIGHT Then
        FloatTextField.HintLabelSmallOffsetX = (FloatTextField.TextField.Width - TextWidth) - (BorderRadius + 5) 'Right
        FloatTextField.lblClear.Left = (FloatTextField.TextField.Width - TextWidth) - (BorderRadius + 5) - 60dip
        FloatTextField.lblV.Left = (FloatTextField.TextField.Width - TextWidth) - (BorderRadius + 5) - 25dip
    Else
        FloatTextField.HintLabelSmallOffsetX = 0dip 'Left
    End If
    FloatTextField.Update
 
    FloatTextField.TextField.SetColorAndBorder(xui.Color_White, DipToCurrent(2), xui.Color_Transparent, BorderRadius)
 
    FloatTextField.lblV.Top = FloatTextField.lblV.Top - 17dip
    FloatTextField.lblClear.Top = FloatTextField.lblClear.Top - 17dip

    Private ed As EditText = FloatTextField.TextField
    ed.Gravity = Gravity.TOP + Gravity.LEFT
    ed.SingleLine = False
    FloatTextField.Update
End Sub

Private Sub MeasureTextWidth(t As String, f As B4XFont) As Float
    Dim cvs As B4XCanvas
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 2dip, 2dip)
    cvs.Initialize(p)
    Dim Width As Float = cvs.MeasureText(t, f).Width
    Return Width
End Sub
...



    Dim sf As Object = PrefDialog.ShowDialog(Item, "OK", Maps.L(23,"CANCEL"))
    For i = 0 To PrefDialog.PrefItems.Size - 1
        Private pi As B4XPrefItem = PrefDialog.PrefItems.Get(i)
        If pi.ItemType = PrefDialog.TYPE_TEXT Then
            Private ft As B4XFloatTextField = PrefDialog.CustomListView1.GetPanel(i).GetView(0).Tag
            Private dp As Int = ft.lblV.Top - 17dip
            ft.TextField.Font = xui.CreateDefaultBoldFont(14)
            Select i
                Case 6
                    PrefDialog.CustomListView1.GetPanel(i).GetView(0).Height = 1000dip 'Height TextField
                    PrefDialog.CustomListView1.ResizeItem(i, 200dip) 'Height PrefItems
                    SetFloatTextField(ft,14,16,14,Gravity.RIGHT) ' -------->>>>> how to get a field scrolled in edit?
                Case Else
                    ft.lblClear.Top = dp: ft.lblV.Top = dp
            End Select
        End If
    Next

    Wait For (sf) Complete (Result As Int)
ScreenShot00009.png
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
?
Vertical scroll action in PrefDialog.TYPE_TEXT
If pi.ItemType = PrefDialog.TYPE_TEXT Then
Change field to :
PrefDialog.TYPE_MULTILINETEXT
Your post:
 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
You cannot nest scrollable controls. Make the text field as tall as needed.

I just managed to fix the problem I submitted in the thread (see: post thread #1)
I've included the source of the working code: PrefDialog.TYPE_MULTILINETEXT.
Despite suggestions (see: post thread #2), I can scroll the field vertically.

Greetings. And once again, many thanks for your help ?

PrefDialog.ShowDialog(Item, "OK", Maps.L(23,"CANCEL")):
Private Sub MeasureTextWidth(t As String, f As B4XFont) As Float
    Dim cvs As B4XCanvas
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 2dip, 2dip)
    cvs.Initialize(p)
    Dim Width As Float = cvs.MeasureText(t, f).Width
    Return Width
End Sub

'Handle keyboard changes.
Private Sub kbd_HeightChanged (NewHeight As Int, OldHeight As Int)
    PrefDialog.KeyboardHeightChanged(NewHeight)
End Sub

. . .

    Dim jo As JavaObject = PrefDialog.CustomListView1.sv
    jo.RunMethod("setVerticalScrollBarEnabled", Array(True))
  
    PrefDialog.CustomListView1.sv.ScrollViewOffsetY = 0

    Dim sf As Object = PrefDialog.ShowDialog(Item, "OK", Maps.L(23,"CANCEL"))
    For i = 0 To PrefDialog.PrefItems.Size - 1
        Private pi As B4XPrefItem = PrefDialog.PrefItems.Get(i)
        If pi.ItemType = PrefDialog.TYPE_TEXT Then
            Private ft As B4XFloatTextField = PrefDialog.CustomListView1.GetPanel(i).GetView(0).Tag
            Private dp As Int = ft.lblV.Top - 17dip
            Private sx As Int = ft.HintLabelSmallOffsetX+2dip
            ft.TextField.Font = xui.CreateDefaultBoldFont(14)
            ft.HintLabelSmallOffsetX = sx
            ft.lblClear.Top = dp: ft.lblV.Top = dp
        Else If pi.ItemType = PrefDialog.TYPE_MULTILINETEXT Then
            Private pl As B4XView = PrefDialog.CustomListView1.GetPanel(i)
            Private ft As B4XFloatTextField = pl.GetView(0).Tag
            Private dp As Int = ft.lblV.Top - 92dip
            Private hg As Int = 200dip 'Changes the height of an existing item (custom view)

            PrefDialog.CustomListView1.ResizeItem(i, hg)

            ft.TextField.Font = xui.CreateDefaultBoldFont(14)
            ft.TextField.SetTextAlignment("TOP","LEFT")
            ft.SmallLabelTextSize = 14 'Hint Small
            ft.LargeLabelTextSize = 16 'Hint Large
            ft.TextField.TextSize = 14 'Text

            Private SmallTextFont  As B4XFont = xui.CreateFont2(ft.HintFont, ft.SmallLabelTextSize)
            Private LargeTextFont  As B4XFont = xui.CreateFont2(ft.HintFont, ft.LargeLabelTextSize)
            Private SmallTextWidth As Int = MeasureTextWidth(ft.HintText, SmallTextFont)
            Private LargeTextWidth As Int = MeasureTextWidth(ft.HintText, LargeTextFont)
            Private BorderRadius   As Int = 0

            ft.HintLabelSmallOffsetY = 3 'Inside
            ft.HintLabelSmallOffsetX = (ft.TextField.Width - SmallTextWidth) - (BorderRadius + 5)      'Right

            If ft.LargeLabelTextSize = ft.SmallLabelTextSize Then
                ft.HintLabelLargeOffsetX = (ft.TextField.Width - LargeTextWidth) - (BorderRadius + 5) 'Right
            Else
                ft.HintLabelLargeOffsetX = (ft.TextField.Width - LargeTextWidth) - (BorderRadius + 5) 'Right
            End If
          
            #If B4A
            Private edt As EditText = ft.TextField
            edt.Padding = Array As Int (4dip, 10dip, 4dip, 4dip) 'Resize Padding
            #End If

            ft.mBase.Width  = ft.mBase.Width
            ft.mBase.Height = hg

            CallSub3(ft, "Base_Resize", ft.mBase.Width, ft.mBase.Height)
          
            ft.TextField.SetColorAndBorder(xui.Color_White, DipToCurrent(2), xui.Color_Transparent, BorderRadius)
            ft.lblClear.Left = (ft.TextField.Width - SmallTextWidth) - (BorderRadius + 5) - 60dip
            ft.lblV.Left = (ft.TextField.Width - SmallTextWidth) - (BorderRadius + 5) - 25dip
            ft.lblV.Top = dp: ft.lblClear.Top = dp
            ft.Update
        End If
    Next

    Wait For (sf) Complete (Result As Int)
 
Last edited:
Upvote 0
Top