Android Question Edittext1.Value ?

DonManfred

Expert
Licensed User
Longtime User
If edittext1.Text = editext2.Text then
...
Ende if
 
Upvote 0

Michael Mc

Member
Licensed User
Longtime 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"
 
Upvote 0

Michael Mc

Member
Licensed User
Longtime 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.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime 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
 
Upvote 0
Top