Android Question Edittext1.Value ?

Michael Mc

Member
Licensed User
Then why this not working ?

If EditText1.Text < 3 Then
...
End If

Because EditTex1.Text is a String Value and 3 is an integer. You would need to convert your EditText1.text to an int prior to comparing it.

You also should have some error checking so that you EditText1.text really is a number and not something like "Hello3"
 

Michael Mc

Member
Licensed User
How to convert edittext to integer

Dim Edittext1 as Int ?
I get error...

if val(Edittext1.text) < 3 then
' I'm lower then 3
else
' I'm greater then 2
end if

To check if Edittext1.text is really a number:
If IsNumber( Edittext1Text) Then .......

The Val() function will also do this for you but will return 0 if .Text is not a real number. So on EditText boxes controls it is best to check that what the user entered is
really a valid number not something else. Sometimes it best just to use a spinner control for numbers only.
 

Peter Simpson

Expert
Licensed User
Here you go @G-ShadoW...
B4X:
Sub Globals
    Dim EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    EditText1.Initialize("ET1")
    Activity.AddView(EditText1, 50dip, 50dip, 100dip, 60dip)
End Sub

Sub ET1_TextChanged (Old As String, New As String)
    Try
        If EditText1.Text < 5 Then ToastMessageShow("Smaller", False)
    Catch
        Log(LastException.Message)
    End Try
End Sub
 
Top