Android Question Field validation status


Active Member
Licensed User
Longtime User
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


Well-Known Member
Licensed User
Longtime 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:

Public Sub checkFields(fields() As EditText) As 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
    Return True
End Sub

<shape xmlns:android=""
    <corners android:radius="0dp" />
    <stroke android:width="1dip" android:color="#FF0000" />

- Colin.
Upvote 0