Java tutorial
//package com.java2s; //License from project: Apache License import android.widget.EditText; import android.widget.Spinner; public class Main { /** * Gets text from an editText, checks if it is valid, trims it, and if it is not = null, * returns a boolean of true/ false * @param et * @return */ public static boolean isFieldValid(EditText et) { String str = et.getText().toString(); if (!str.equals(null)) { str = str.trim(); if (!str.equalsIgnoreCase("")) { if (!str.isEmpty()) { return true; } } } return false; } /** * Gets text from a spinner, checks if it is valid, trims it, and if it is not = null, * returns a boolean of true/ false * @param spinner * @return */ public static boolean isFieldValid(Spinner spinner) { String str = spinner.getSelectedItem().toString(); if (!str.equals(null)) { str = str.trim(); if (!str.equalsIgnoreCase("")) { return true; } } return false; } }