Android Question Field validation status

ocalle

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

Computersmith64

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:

B4X:
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
    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.
 
Upvote 0
Top