Android Question Field validation status

Discussion in 'Android Questions' started by ocalle, May 12, 2019.

  1. ocalle

    ocalle Active Member Licensed User

    Hi
    Is there any way to validate an entry in an edittext or spinner?, that is to say when you leave the focus checks its validation and changes color or a tilde?
    Useful I think when you have to fill many fields
    Thanks in advance
     
  2. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    I don't think there's anything built in. For EditTexts in one of my apps I have a utility function that I pass an array of EditTexts to & check if they are empty. It returns False if any of them is empty & True if they all aren't. If one of them is empty it draws a red border around it:

    Code:
    Public Sub checkFields(fields() As EditTextAs Boolean
        
    Private xl As XmlLayoutBuilder
      
        
    For Each field As EditText In fields
            
    If field.Text = "" Then
                field.Background = xl.GetDrawable(
    "edittexterror")
                
    Return False
            
    End If
        
    Next
        
    Return True
    End Sub

    'edittexterror.xml
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape=
    "rectangle">
        <corners android:radius=
    "0dp" />
        <stroke android:width=
    "1dip" android:color="#FF0000" />
    </shape>
    - Colin.
     
    ocalle and José J. Aguilar like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    ocalle 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