Handler for an Android form to calculate a cross product
I expect x/y 1-3 are textfields, though not enough context to be entirely certain, going from that assumption:


Create a helper method to check for value:

private boolean hasValue(TextField field) {
    return !field.getText().toString().isEmpty();
}

Store all textfields in an array.
Loop through and validate each one.

for (TextField field : textFields) {
   if (!hasValue(field)) {
      field.setError("needs value");
      field.requestFocus();
   }
}



Depending on your needs, I would apply this to use break, and perhaps apply it as a boolean returning method that ensures a validated state before continuing application logic.


Once the validation is done and completed (why a boolean returning method for step 3 could be helpful), proceed with the application logic.