0

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.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
Maya
  • 3
  • 2

4 Answers4

1

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?

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
1

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
                        }
                    }
});
Sagar Patil
  • 1,400
  • 15
  • 29
0

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.....
  }
});
baboo
  • 1,983
  • 17
  • 23
0

There Are 2 Ways to Validate

  1. at each Field Validation
  2. 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

    • Email formate is invalid
    • Email not entered
    • empty field
    • not followed Sequence etc
Anu
  • 1,884
  • 14
  • 30
Usman Kurd
  • 7,212
  • 7
  • 57
  • 86