Android form validation UI library
The pop-up effect you have shown on your screenshot can be achieved using Android's built-in setError(String)
method on EditText
widgets.
Also, you can leverage the power of annotations using the Android Saripaar library that I've authored.
first add the library:
compile 'com.mobsandgeeks:android-saripaar:2.0.2'
The library is very simple to use. In your activity annotate the View
references you would like to validate as in the following example.
@Order(1)private EditText fieldEditText;@Order(2)@Checked(message = "You must agree to the terms.")private CheckBox iAgreeCheckBox;@Order(3)@Length(min = 3, message = "Enter atleast 3 characters.")@Pattern(regex = "[A-Za-z]+", message = "Should contain only alphabets")private TextView regexTextView;@Order(4)@Password(min = 6, scheme = Password.Scheme.ALPHA_NUMERIC_MIXED_CASE_SYMBOLS)private EditText passwordEditText;@Order(5)@ConfirmPasswordprivate EditText confirmPasswordEditText;
The order
attribute specifies the order in which the fields have to be validated.
In your onCreate()
method instantiate a new Validator
object. and call validator.validate()
inside any of your event listeners.
You'll receive callbacks on onSuccess
and onFailure
methods of the ValidationListener
.
If you want to show a pop-up as show in the image above then do the following,
public void onValidationFailed(View failedView, Rule<?> failedRule) { if (failedView instanceof Checkable) { Toast.makeText(this, failedRule.getFailureMessage(), Toast.LENGTH_SHORT).show(); } else if (failedView instanceof TextView) { TextView view = (TextView) failedView; view.requestFocus(); view.setError(failedRule.getFailureMessage()); }}
Hope that helps.
Android has extremely easy-to-use built-in validation mechanism which is great enough. See the following link:http://blog.donnfelker.com/2011/11/23/android-validation-with-edittext/
I've just come across ValidationKomensky that you may find useful