Java Code Examples for android.widget.EditText#setError()
The following examples show how to use
android.widget.EditText#setError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoCollectionTemplate.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static boolean validated(Context context, EditText link) { if (link == null) { return false; } String linkText = link.getText().toString().trim(); if ("".equals(linkText)) { link.setError(context.getString(R.string.video_collection_template_link_hint)); return false; } else if (!(linkText.contains(YOUTUBE + ".com") || linkText.contains(YOUTUBE_SHORT) || linkText.contains(DAILYMOTION + ".com") || linkText.contains(VIMEO + ".com"))) { link.setError(context.getString(R.string.video_collection_template_linited_links)); return false; } return true; }
Example 2
Source File: LoginActivity.java From MangoBloggerAndroidApp with Mozilla Public License 2.0 | 6 votes |
private boolean validateForm(EditText emailField, EditText passwordField) { boolean result = true; if (TextUtils.isEmpty(emailField.getText().toString())) { emailField.setError("Required"); result = false; } else { emailField.setError(null); } if (TextUtils.isEmpty(passwordField.getText().toString())) { passwordField.setError("Required"); result = false; } else { passwordField.setError(null); } return result; }
Example 3
Source File: Validation.java From DeviceInfo with Apache License 2.0 | 6 votes |
public static boolean isValid(EditText editText, String regex, String errMsg, boolean required) { String text = editText.getText().toString().trim(); // clearing the error, if it was previously set by some other values editText.setError(null); // text required and editText is blank, so return false if (required && !hasText(editText)) return false; // pattern doesn't match so returning false if (required && !Pattern.matches(regex, text)) { editText.setError(errMsg); return false; } ; return true; }
Example 4
Source File: FloatMeasurementView.java From openScale with GNU General Public License v3.0 | 6 votes |
private float validateAndGetInput(View view) { EditText editText = view.findViewById(R.id.float_input); String text = editText.getText().toString(); float newValue = -1; if (text.isEmpty()) { editText.setError(getResources().getString(R.string.error_value_required)); return newValue; } try { newValue = Float.valueOf(text.replace(',', '.')); } catch (NumberFormatException ex) { newValue = -1; } if (newValue < 0 || newValue > getMaxValue()) { editText.setError(getResources().getString(R.string.error_value_range)); newValue = -1; } return newValue; }
Example 5
Source File: FlashTemplate.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private boolean validateData(EditText question, EditText answer, Context context) { String questionText = question.getText().toString().trim(); String answerText = answer.getText().toString().trim(); if ("".equals(questionText)) { question.setError(context.getString(R.string.enter_question)); return false; } else if ("".equals(answerText)) { answer.setError(context.getString(R.string.enter_answer)); return false; } else if (!mIsPhotoAttached) { Toast.makeText(context, context.getString(R.string.flash_template_attach_image), Toast.LENGTH_SHORT).show(); return false; } return true; }
Example 6
Source File: WidgetThemeConfigActivity.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
protected static boolean validateThemeID(Context context, EditText editName, boolean grabFocus ) { boolean isValid = true; editName.setError(null); String themeID = editName.getText().toString().trim(); if (themeID.isEmpty()) { isValid = false; // themeName is required editName.setError(context.getString(R.string.edittheme_error_themeName_empty)); if (grabFocus) editName.requestFocus(); } if (mode == UIMode.ADD_THEME && WidgetThemes.valueOf(editName.getText().toString()) != null) { isValid = false; // themeName is already taken editName.setError(context.getString(R.string.edittheme_error_themeName_unique)); if (grabFocus) editName.requestFocus(); } return isValid; }
Example 7
Source File: ComprehensionTemplate.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static boolean validated( Context context, EditText title, EditText passage, EditText timer) { if (title == null || passage == null || timer == null) { return false; } String titleText = title.getText().toString().trim(); String passageText = passage.getText().toString().trim(); String timerText = timer.getText().toString().trim(); if ("".equals(titleText)) { title.setError(context.getString(R.string.comprehension_template_title_hint)); return false; } else if ("".equals(passageText)) { passage.setError(context.getString(R.string.comprehension_template_passage_hint)); return false; }else if (timerText.length() > 9) { timer.setError(context.getString(R.string.comprehension_template_timer_correct_hint)); return false; }else if ("0".equals(timerText)) { timer.setError((context.getString(R.string.time_zero_error))); return false; } else if ("".equals(timerText)) { timer.setError(context.getString(R.string.comprehension_template_timer_hint)); return false; } return true; }
Example 8
Source File: AddEditTaskFragment.java From android-espresso-revealed with Apache License 2.0 | 5 votes |
@Override public void showEmptyTaskError() { Snackbar snackbar = Snackbar.make(contentView, getString(R.string.empty_task_message), Snackbar.LENGTH_SHORT); snackbar.show(); EditText title = getActivity().findViewById(R.id.add_task_title); title.setError(getResources().getString(R.string.add_task_empty_title)); title.setHintTextColor(Color.RED); }
Example 9
Source File: RescueCodeInputHelper.java From secure-quick-reliable-login with MIT License | 5 votes |
private boolean checkEditText(EditText code, String verify) { String check = code.getText().toString(); if(check.length() != 4) return false; boolean correct = true; if (verify != null) { if (!check.equals(verify)) { correct = false; } } try { Integer.parseInt(check); } catch (NumberFormatException nfe) { correct = false; } if (!correct) { code.setError(mContext.getResources().getString( R.string.rescue_code_incorrect)); return false; } code.setError(null); View nextFocusDown = mLayoutRoot.findViewById(code.getNextFocusDownId()); if (nextFocusDown != null) nextFocusDown.requestFocus(); return true; }
Example 10
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void hasErrorTextReturnsFalse_WithDifferentErrorString() { EditText editText = new EditText(context); editText.setError("TEST"); assertFalse(hasErrorText("TEST1").matches(editText)); }
Example 11
Source File: EditTexts.java From convalida with Apache License 2.0 | 5 votes |
public static void removeError(EditText editText) { TextInputLayout layout = getTextInputLayout(editText); if (layout != null) { layout.setErrorEnabled(false); layout.setError(null); } else { editText.setError(null); } }
Example 12
Source File: LoginActivity.java From STUer-client with MIT License | 5 votes |
private boolean isEmpty(EditText et) { if (TextUtils.isEmpty(et.getText())) { et.setError("不能为空"); return true; } return false; }
Example 13
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 检测EditText内容是否为空,若为空则进行警告提醒 * * @param et * @param msg * @return */ public static boolean showEditTextWarning(EditText et, String msg) { if (TextUtils.isEmpty(et.getText())) { et.setError(msg); et.requestFocus(); et.setText(""); return true; } return false; }
Example 14
Source File: UploadFragment.java From abelana with Apache License 2.0 | 5 votes |
/** * Uploads the new photo to the backend. */ private void uploadNewPhoto() { EditText editText = (EditText) getActivity().findViewById(R.id .editTextUploadDescription); String description = editText.getText().toString(); String error = ""; if(!description.equals("") && mBitmap != null) { new UploadTask().execute(description); } else { if(description.equals("")) { editText.setError(getString(R.string .upload_photo_description_missing)); error += getString(R.string.upload_photo_description_missing); } if (mBitmap == null) { if(!error.equals("")) { error += "\n"; } error += getString(R.string.upload_photo_photo_missing); } new AlertDialog.Builder(getActivity()) .setTitle(getString(R.string .upload_photo_error_dialog_title)) .setMessage(error) .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }) .setIcon(R.drawable.ic_error_black_48dp) .show(); } }
Example 15
Source File: OdooAccountQuickManage.java From framework with GNU Affero General Public License v3.0 | 5 votes |
private void savePassword() { edtPassword = (EditText) findViewById(R.id.newPassword); edtPassword.setError(null); if (TextUtils.isEmpty(edtPassword.getText())) { edtPassword.setError("Password required"); edtPassword.requestFocus(); } user.setPassword(edtPassword.getText().toString()); loginProcess = new LoginProcess(); loginProcess.execute(user.getDatabase(), user.getHost()); }
Example 16
Source File: OdooAccountQuickManage.java From hr with GNU Affero General Public License v3.0 | 5 votes |
private void savePassword() { edtPassword = (EditText) findViewById(R.id.newPassword); edtPassword.setError(null); if (TextUtils.isEmpty(edtPassword.getText())) { edtPassword.setError("Password required"); edtPassword.requestFocus(); } user.setPassword(edtPassword.getText().toString()); loginProcess = new LoginProcess(); loginProcess.execute(user.getDatabase(), user.getHost()); }
Example 17
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void hasErrorTextReturnsTrue_WithCorrectErrorString() { EditText editText = new EditText(context); editText.setError("TEST"); assertTrue(hasErrorText("TEST").matches(editText)); }
Example 18
Source File: Validation.java From DeviceInfo with Apache License 2.0 | 5 votes |
public static boolean hasText(EditText editText) { String text = editText.getText().toString().trim(); editText.setError(null); // length 0 means there is no text if (text.length() == 0) { editText.setError(REQUIRED_MSG); return false; } return true; }
Example 19
Source File: EditTextErrorHandler.java From FormValidations with Apache License 2.0 | 4 votes |
@Override public void handleError(@NonNull final FieldValidationException e) { final EditText textView = e.getTextView(); final String message = e.getMessage(); textView.setError(message); }
Example 20
Source File: OdooLogin.java From framework with GNU Affero General Public License v3.0 | 4 votes |
private void loginUser() { Log.v("", "LoginUser()"); String serverURL = createServerURL((mSelfHostedURL) ? edtSelfHosted.getText().toString() : OConstants.URL_ODOO); String databaseName; edtUsername = (EditText) findViewById(R.id.edtUserName); edtPassword = (EditText) findViewById(R.id.edtPassword); if (mSelfHostedURL) { edtSelfHosted.setError(null); if (TextUtils.isEmpty(edtSelfHosted.getText())) { edtSelfHosted.setError(OResource.string(this, R.string.error_provide_server_url)); edtSelfHosted.requestFocus(); return; } if (databaseSpinner != null && databases.size() > 1 && databaseSpinner.getSelectedItemPosition() == 0) { Toast.makeText(this, OResource.string(this, R.string.label_select_database), Toast.LENGTH_LONG).show(); findViewById(R.id.controls).setVisibility(View.VISIBLE); findViewById(R.id.login_progress).setVisibility(View.GONE); return; } } edtUsername.setError(null); edtPassword.setError(null); if (TextUtils.isEmpty(edtUsername.getText())) { edtUsername.setError(OResource.string(this, R.string.error_provide_username)); edtUsername.requestFocus(); return; } if (TextUtils.isEmpty(edtPassword.getText())) { edtPassword.setError(OResource.string(this, R.string.error_provide_password)); edtPassword.requestFocus(); return; } findViewById(R.id.controls).setVisibility(View.GONE); findViewById(R.id.login_progress).setVisibility(View.VISIBLE); mLoginProcessStatus.setText(OResource.string(OdooLogin.this, R.string.status_connecting_to_server)); if (mConnectedToServer) { databaseName = databases.get(0); if (databaseSpinner != null) { databaseName = databases.get(databaseSpinner.getSelectedItemPosition()); } mAutoLogin = false; loginProcess(databaseName); } else { mAutoLogin = true; try { Odoo.createInstance(OdooLogin.this, serverURL).setOnConnect(OdooLogin.this); } catch (OdooVersionException e) { e.printStackTrace(); } } }