'What should be the pixel width of a label/textfield that can have a maximum of n characters of a particular font and size?
Private Sub computeWidth(n As Int, fnt As B4XFont) As Int
Dim testString As String = "XXXXXXXXXX"
Dim cv As B4XCanvas 'ignore, since we don't need to initialize it for this purpose
Dim w As Float = cv.MeasureText(testString, fnt).width
Return Floor((n + 1) * w / 10)
End Sub
Public Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Dim fnt As B4XFont = xui.CreateDefaultFont(11)
Dim tf As TextField
tf.Initialize("input")
Dim tfx As B4XView = tf
tfx.Font = fnt
tfx.Text = "The World Turns"
Root.AddView(tf, 100, 200, tf.Width, 30)
'After added to the panel the view is fully formed and can be modified
tfx.Width = computeWidth(tfx.Text.Length, fnt)
tfx.RequestFocus
tfx.SetSelection(tfx.Text.Length, 0)
End Sub