Android Question B4XFloatTextField filter characters allowed

tsteward

Well-Known Member
Licensed User
Longtime User
I'm loving the B4XFloatTextField and can't figure out how to limit what characters and text length the user can input.
My app will provide a string of the allowed characters and field length as this varies all the time.

Any help appreciated
 
Search the for forum for IME you will find the necessary methods (e.g. SetLengthFilter) in that library.
Using a standard edittext was easy but can't figure out how to do it using B4XFloatTextField

Standard edit text my code was
ime.SetCustomFilter(EdTxtCode, EdTxtCode.INPUT_TYPE_TEXT, chars)
 
Upvote 0
If I recall correctly, the B4XFloattextfield exposes the underlying textbox as a property.
Code: Copy
ime.SetCustomFilter(B4XEdTxtCode.TextField, EdTxtCode.INPUT_TYPE_TEXT, chars)
Again, search the forum for IME you will find many helpful posts.
 
Upvote 0
If I recall correctly, the B4XFloattextfield exposes the underlying textbox as a property.
Code: Copy
ime.SetCustomFilter(B4XEdTxtCode.TextField, EdTxtCode.INPUT_TYPE_TEXT, chars)
Again, search the forum for IME you will find many helpful posts.
I have searched and I have not found a solution for me.

The parameters
EdTxtCode.INPUT_TYPE_TEXT is not valid
EdTxtCode.TextField.INPUT_TYPE_TEXT is also not valid
 
Upvote 0
If you wish to use the constants, you will need to cast the B4XView to the appropriate view type:
Code: Copy
Dim poTxt As EditText
poTxt = B4XEdTxtCode.TextField ' view is B4XFloatTextField and the .TextField property is B4XView not EditText
ime.SetCustomFilter(poTxt, poTxt.INPUT_TYPE_TEXT, chars)
 
Upvote 0
You can get the standard textfiel by

B4X: Copy
Dim et As EditText = B4XFloatTextField1.TextField
'modify "et" as needed
 
Upvote 0
Use the Tag property of the B4XFloatEdit With the Tag property in 10 characters for example the code would be:

B4X: Copy
Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    If New.Length > B4XFloatTextField1.Tag Then
        B4XFloatTextField1.Text = New.Substring2(0, B4XFloatTextField1.Tag)
    End If
End Sub

It should work.
 
Upvote 0
Use the Tag property of the B4XFloatEdit With the Tag property in 10 characters
I think you are missing some code. It should be like this:. Please confirm or refute:
Code: Copy
Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    If New.Length > B4XFloatTextField1.Tag Then   'the tag has the max number of characters
        B4XFloatTextField1.Text = New.Substring2(0, B4XFloatTextField1.Tag)
        Dim et As EditText = B4XFloatTextField1.TextField
        et.SelectionStart = et.text.Length
    End If
End Sub
 
Upvote 0
The lines you mention serve to place the cursor at the end of the text.

The code I make only blocks the number of characters.

Your code seems much better. Thank you
 
Upvote 0
Back
Top