/** * Method to get text of the EditText View * * @param editText * @return String text * @throws ViewException */ public static String getText(EditText editText) { String text = ""; try { validNull(editText); text = editText.getText().toString().trim(); } catch (ViewException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } return text; }
/** * Method to set blank error to editTexts * * @param editTexts * @throws ViewException */ public static void setBlankError(EditText... editTexts) { if (editTexts == null || editTexts.length == 0) { try { throw new ViewException(ViewException.MessageType.NULL); } catch (ViewException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } } for (EditText editText : editTexts) { editText.setError(null); } }
/** * Method to validate if the list EditText Views is blank * * @param editTexts * @return Boolean * @throws ViewException */ public static boolean isBlank(EditText... editTexts) { if (editTexts == null || editTexts.length == 0) { try { throw new ViewException(ViewException.MessageType.NULL); } catch (ViewException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } } for (EditText editText : editTexts) { String text = getText(editText); if (text.equalsIgnoreCase("")) { return true; } } return false; }
/** * Method to verify if a editText is number * * @param editTexts * @return * @throws ViewException */ public static boolean isNumber(EditText... editTexts) { if (editTexts == null || editTexts.length == 0) { try { throw new ViewException(ViewException.MessageType.NULL); } catch (ViewException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } } for (EditText editText : editTexts) { String text = getText(editText); try { Integer.parseInt(text); } catch (Exception e) { return false; } } return true; }