本文整理匯總了Java中android.widget.EditText.setError方法的典型用法代碼示例。如果您正苦於以下問題:Java EditText.setError方法的具體用法?Java EditText.setError怎麽用?Java EditText.setError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.EditText
的用法示例。
在下文中一共展示了EditText.setError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: attemptLogin
import android.widget.EditText; //導入方法依賴的package包/類
private void attemptLogin() {
EditText password_edit = (EditText) findViewById(R.id.pin_login_password);
// Reset errors.
password_edit.setError(null);
// Store values at the time of the login attempt.
String password = password_edit.getText().toString();
// Check for a valid password, if the user entered one.
if (TextUtils.isEmpty(password)) {
password_edit.setError(getString(R.string.error_field_required));
password_edit.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
showProgress(true);
new ProfilePinLoginActivity.PinLoginTask(password).execute((Void) null);
}
}
示例2: onInput
import android.widget.EditText; //導入方法依賴的package包/類
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
if (mIsFirstTextChanged) {
mIsFirstTextChanged = false;
return;
}
EditText editText = dialog.getInputEditText();
if (editText == null)
return;
int errorResId = 0;
if (input == null || input.length() == 0) {
errorResId = R.string.text_name_should_not_be_empty;
} else if (!input.equals(mExcluded)) {
if (new File(getCurrentDirectory(), mExtension == null ? input.toString() : input.toString() + mExtension).exists()) {
errorResId = R.string.text_file_exists;
}
}
if (errorResId == 0) {
editText.setError(null);
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
} else {
editText.setError(getString(errorResId));
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
}
}
示例3: isValid
import android.widget.EditText; //導入方法依賴的package包/類
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;
}
示例4: isEnteredTextValid
import android.widget.EditText; //導入方法依賴的package包/類
private static boolean isEnteredTextValid(Context context, EditText editText, int resFieldName, int maxLength, boolean checkName) {
boolean isCorrect;
Pattern p;
if (checkName) {
p = Pattern.compile("^[a-zA-Z][a-zA-Z 0-9]{2," + (maxLength - 1) + "}+$");
} else {
p = Pattern.compile("^[a-zA-Z][a-zA-Z0-9]{2," + (maxLength - 1) + "}+$");
}
Matcher m = p.matcher(editText.getText().toString().trim());
isCorrect = m.matches();
if (!isCorrect) {
editText.setError(String.format(context.getString(R.string.error_name_must_not_contain_special_characters_from_app),
context.getString(resFieldName),
maxLength));
return false;
} else {
return true;
}
}
示例5: redirectUserToAuthorizeAndLogin
import android.widget.EditText; //導入方法依賴的package包/類
private void redirectUserToAuthorizeAndLogin(EditText editText) {
/* To authorize this app and log in it's necessary to redirect to the domain given,
* activity_login there, and the server will redirect back to the app with its response. */
String endpoint = MastodonApi.ENDPOINT_AUTHORIZE;
String redirectUri = getOauthRedirectUri();
Map<String, String> parameters = new HashMap<>();
parameters.put("client_id", clientId);
parameters.put("redirect_uri", redirectUri);
parameters.put("response_type", "code");
parameters.put("scope", OAUTH_SCOPES);
String url = "https://" + domain + endpoint + "?" + toQueryString(parameters);
Uri uri = Uri.parse(url);
if (!openInCustomTab(uri, this)) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
if (viewIntent.resolveActivity(getPackageManager()) != null) {
startActivity(viewIntent);
} else {
editText.setError(getString(R.string.error_no_web_browser_found));
}
}
}
示例6: checkPasswordsMatch
import android.widget.EditText; //導入方法依賴的package包/類
private void checkPasswordsMatch( final EditText mPasswordConfirmText ) {
// Check if passwords match
if (!StringValidator.checkPasswords(tempPass, tempPassConfirm)) {
errorFlag = true;
mPasswordConfirmText.setError(getString(R.string.sign_up_non_matching_passwords));
mPasswordConfirmText.requestFocus();
} else
mPasswordConfirmText.setError(null);
}
示例7: checkEmptyText
import android.widget.EditText; //導入方法依賴的package包/類
private boolean checkEmptyText(EditText txt) {
if(TextUtils.isEmpty(txt.getText().toString())) {
txt.setError("Empty");
return false;
}
txt.setError(null);
return true;
}
示例8: checkValidFirstName
import android.widget.EditText; //導入方法依賴的package包/類
private void checkValidFirstName( final EditText mFirstNameText ) {
// Check first name for valid alpha and non empty
if (tempFirstName.isEmpty()){
errorFlag = true;
mFirstNameText.setError(getString(R.string.sign_up_missing_name));
} else if (!StringValidator.isAlpha(tempFirstName)){
errorFlag = true;
mFirstNameText.setError(getString(R.string.sign_up_invalid_name));
} else
mFirstNameText.setError(null);
}
示例9: validate
import android.widget.EditText; //導入方法依賴的package包/類
boolean validate(EditText editText) {
if (editText.getText().toString().length() == 0) {
editText.setError("Field Required");
editText.requestFocus();
}
return editText.getText().toString().length() > 0;
}
示例10: onPostExecute
import android.widget.EditText; //導入方法依賴的package包/類
@Override
protected void onPostExecute(final Boolean success) {
EditText password_edit = (EditText) findViewById(R.id.pin_login_password);
if (success) {
Intent intent = new Intent(ProfilePinLoginActivity.this, MainActivity.class);
startActivity(intent);
showProgress(false);
} else {
showProgress(false);
if (mLoginError == IExchangeAPI.ErrorOrPayload.ERROR_NONE) {
password_edit.setError(getString(R.string.error_no_response));
password_edit.requestFocus();
} else {
switch (mLoginError) {
case IExchangeAPI.ErrorOrPayload.ERROR_NOT_CONNECTED:
password_edit.setError(getString(R.string.error_no_connectivity));
password_edit.requestFocus();
break;
case IExchangeAPI.ErrorOrPayload.ERROR_LOGIN_PASS:
password_edit.setError(getString(R.string.error_incorrect_password));
password_edit.requestFocus();
break;
case IExchangeAPI.ErrorOrPayload.ERROR_UNAUTHORIZED:
password_edit.setError(getString(R.string.error_unauthorized));
password_edit.requestFocus();
break;
case IExchangeAPI.ErrorOrPayload.ERROR_UNKNOWN:
password_edit.setError(getString(R.string.error_unknown));
password_edit.requestFocus();
break;
}
}
}
}
示例11: checkValidMiddleName
import android.widget.EditText; //導入方法依賴的package包/類
private void checkValidMiddleName( final EditText mMiddleNameText ) {
// Check middle name for valid alpha
if (!StringValidator.isAlpha(tempMiddleName) && !tempMiddleName.isEmpty()){
errorFlag = true;
mMiddleNameText.setError(getString(R.string.sign_up_invalid_name));
} else
mMiddleNameText.setError(null);
}
示例12: onNextButtonClick
import android.widget.EditText; //導入方法依賴的package包/類
@ActionHandler(layoutResource = R.id.next_button)
public void onNextButtonClick(View v){
EditText passwordEditText = (EditText)findViewById(R.id.password);
EditText passwordConfirm1 = (EditText)findViewById(R.id.password_confirm);
EditText usernameEdit = (EditText)findViewById(R.id.username_edittext);
String errorMessageLength = "password length should be greater than 3";
String errorMessageMatch = "password does not match";
CharSequence sequence = passwordEditText.getText();
CharSequence sequenceConfirm = passwordConfirm1.getText();
if(usernameEdit.getText().toString().length()<1){
usernameEdit.setError("Please give me your name");
return;
}
mUserName=usernameEdit.getText().toString();
if(isValidPassword(sequence)){
if(sequence.toString().equals(sequenceConfirm.toString())) {
mUserSecretDatabase=sequence.toString();
Boolean permission=checkPermissions();
if(permission){
new DatabaseSetupTask().execute();
}
}else{
passwordConfirm1.setError(errorMessageMatch);
}
}else{
passwordEditText.setError(errorMessageLength);
}
}
示例13: isFieldEmpty
import android.widget.EditText; //導入方法依賴的package包/類
private boolean isFieldEmpty(EditText formField) {
if (TextUtils.isEmpty(formField.getText().toString())) {
formField.setError(getString(R.string.error_field_required));
return true;
}
return false;
}
示例14: checkEditText
import android.widget.EditText; //導入方法依賴的package包/類
public static boolean checkEditText(EditText editText, String name, boolean required, int length) {
String text = text(editText);
if (isEmpty(text) && required) {
editText.setError("Please specify the "+name+"..");
return false;
}
if (text != null && text.length() > length) {
editText.setError("Length of the "+name+" must not be more than "+length+" chars..");
return false;
}
return true;
}
示例15: checkInvalidPassword
import android.widget.EditText; //導入方法依賴的package包/類
private void checkInvalidPassword( final EditText mPasswordText ) {
// Check if password is invalid
if (!StringValidator.isValidPassword(tempPass)) {
errorFlag = true;
mPasswordText.setError(getString(R.string.sign_up_invalid_password));
mPasswordText.requestFocus();
} else
mPasswordText.setError(null);
}