Android Question Edittext1.Value ?

Discussion in 'Android Questions' started by G-ShadoW, May 11, 2015.

  1. G-ShadoW

    G-ShadoW Active Member Licensed User

    How to compare value between 2 edittext ?
     
  2. DonManfred

    DonManfred Expert Licensed User

    If edittext1.Text = editext2.Text then
    ...
    Ende if
     
  3. G-ShadoW

    G-ShadoW Active Member Licensed User

    Then why this not working ?

    If EditText1.Text < 3 Then
    ...
    End If
     
  4. Michael Mc

    Michael Mc Member Licensed User


    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"
     
  5. G-ShadoW

    G-ShadoW Active Member Licensed User

    How to convert edittext to integer

    Dim Edittext1 as Int ?
    I get error...
     
  6. Michael Mc

    Michael Mc Member Licensed User


    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.
     
    DonManfred likes this.
  7. G-ShadoW

    G-ShadoW Active Member Licensed User

    Thank you
     
  8. Peter Simpson

    Peter Simpson Expert Licensed User

    Here you go @G-ShadoW...
    Code:
    Sub Globals
        
    Dim EditText1 As EditText
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        EditText1.Initialize(
    "ET1")
        
    Activity.AddView(EditText1, 50dip50dip100dip60dip)
    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
     
    DonManfred and G-ShadoW like this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    There is no Val keyword in B4A. The compiler will automatically parse the string to a number. You can use IsNumber to test whether a string can be safely parsed as a number.
     
    Peter Simpson likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice