what method should i use to validate a login registration form in android ?
The validation should take place once the user moves on to the next edittext.
what method should i use to validate a login registration form in android ?
The validation should take place once the user moves on to the next edittext.
I am sure you want to validate values being entered by user in EditText, if this is the case then you can implement TextWatcher for the EditText.
Check this thread: How to use the TextWatcher class in Android?
Try to use setOnFocusChangeListener of the EditText.
Set your validation code in onFocusChange of setOnFocusChangeListener. Once your focus is off then the code/your validation will execute.
Have a look at the following code.
edittext.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View v, boolean hasFocus)
{
if(!hasFocus)
{
// your validation code
}
}
});
Based on your requirement .. Do validation when editText loses focus ...
edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
}else
// Do validation here.....
}
});
There Are 2 Ways to Validate
on Button
click Validation
for Type One you need to Implement TextWatcher
for each Field
sample Snippet is Following
EdittextFieldName.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
and for type 2 You need to check field Data Validations According to filed Type like