Android Question how to set edittext.length = 0

yes

Member
Licensed User
i want to reset variable from different modules. lets say variable a is initially has 0 and then i set it to 5. after some activity i want to reset its value. can i use a.length / javaobject/reflector? and how do i write it?
i got this error when i tried to write a.length = 0

B4A line: 43
edtText1.Text.Length = 0
javac 1.8.0_131
shell\src\KCSoft\TwoLayouts\main_subs_0.java:73: error: unexpected type
main.mostCurrent._edttext1.runMethod(true,"getText").runMethod(true,"length") = BA.numberCast(int.class, 0);
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
You can Handle it with a LegthFilter on your EdditText.
B4X:
Sub Globals
    Dim IME As IME
    Dim edtTest As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)Activity.LoadLayout("layout1")
edtTest.Color=Colors.Red
IME.Initialize("IME")
IME.SetLengthFilter(edtTest, 20)
End Sub
 
  • Like
Reactions: yes
Upvote 0

yes

Member
Licensed User
You can Handle it with a LegthFilter on your EdditText.
B4X:
Sub Globals
    Dim IME As IME
    Dim edtTest As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)Activity.LoadLayout("layout1")
edtTest.Color=Colors.Red
IME.Initialize("IME")
IME.SetLengthFilter(edtTest, 20)
End Sub
thank you sir. i understand this code only apply for edit text. so can this library filter length for string? .if possible for all variable types
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I do not know a method to add a string, a maximum value.

The only thing you can do is to check the length and if it exceeds the maximum value, then give an error message or set the value to empty "". Or you check the length and you simply remove the superfluous character.
 
Upvote 0

yes

Member
Licensed User
I don't understand what exactly you want to do with edtText1.Text.Length = 0 ?
Set it simply to edtText1.Text = ""
And edtText1.Text.Length will be 0.
thanks but i wonder if i can clear variable with javaobject / refelector?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
If you want to reset a string, just set it to "" & then you can check for that value:
B4X:
    Private thisString as String = "A String"
    ...
    thisString = ""
    ....
    If thisString = "" Then
        Log("thisString is empty!")
    End If

- Colin.
 
  • Like
Reactions: yes
Upvote 0
Top