Forcing User to Input Something in EditText in Android

android, android-edittext

Solution

You can add Validation on submit button click:

private boolean validateFields() {
    int yourDesiredLength = 5;
    if (yourEditText1.getText().length() < yourDesiredLength) {
        yourEditText1.setError("Your Input is Invalid");           
        return false;
    }else if (yourEditText2.getText().length() < yourDesiredLength) {
        yourEditText1.setError("Your Input is Invalid");           
       return false;
    } 
    else{
        return true;
    }

On Submit button Click:

btnSubmit.setOnclickListener(new View.OnClickListener){
  @Override
        public void onClick(View v) {
            if(validateFields()){
                // Then Submit 
            }
        }
});

Output will be like this. Photo Credit.

Hope this helps.

Problem

I have several EditTexts in my Activty and I want my users to give inputs correctly before submitting the form. How can I do It? I have also spinners and RadioGroup Button.

Original source