Java Code Examples for android.widget.TextView.setError()

The following are Jave code examples for showing how to use setError() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: buildAPKsSamples   File: CreateGestureActivity.java   View Source Code Vote up 6 votes
@SuppressWarnings({"UnusedDeclaration"})
public void addGesture(View v) {
    if (mGesture != null) {
        final TextView input = (TextView) findViewById(R.id.gesture_name);
        final CharSequence name = input.getText();
        if (name.length() == 0) {
            input.setError(getString(R.string.error_missing_name));
            return;
        }

        final GestureLibrary store = GestureBuilderActivity.getStore();
        store.addGesture(name.toString(), mGesture);
        store.save();

        setResult(RESULT_OK);

        final String path = new File(Environment.getExternalStorageDirectory(),
                "gestures").getAbsolutePath();
        Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();
    } else {
        setResult(RESULT_CANCELED);
    }

    finish();
    
}
 
Example 2
Project: sticky-linear-layout-demo   File: UserValidator.java   View Source Code Vote up 6 votes
protected ValidationResult validateId(String dataString, View ui, int textViewId) {

        TextView textView = (TextView) ui.findViewById(textViewId);

        if (TextUtils.isEmpty(dataString)) {
            textView.setError(null);
            return new ValidationResult(textView, ValidationResult.Validity.UNKNOWN);

        } else {
            if (dataString.length() != 6) {
                textView.setError("Please type in 6 digits ID");
                return new ValidationResult(textView, ValidationResult.Validity.ERROR);
            }
            try {
                Integer.parseInt(dataString);
            } catch (Throwable t) {
                textView.setError("Please type in 6 digits ID");
                return new ValidationResult(textView, ValidationResult.Validity.ERROR);
            }
            textView.setError(null);
            return new ValidationResult(textView, ValidationResult.Validity.VALID);
        }
    }
 
Example 3
Project: sticky-linear-layout-demo   File: AddressValidator.java   View Source Code Vote up 6 votes
protected ValidationResult validateZip(String dataString, View ui, int textViewId) {

        TextView textView = (TextView) ui.findViewById(textViewId);

        if (TextUtils.isEmpty(dataString)) {
            textView.setError(null);
            return new ValidationResult(textView, ValidationResult.Validity.UNKNOWN);

        } else {
            if (dataString.length() != 5) {
                textView.setError("Please type in 5 digit ZIP code");
                return new ValidationResult(textView, ValidationResult.Validity.ERROR);
            }
            try {
                Integer.parseInt(dataString);
            } catch (Throwable t) {
                textView.setError("Please type in 5 digit ZIP code");
                return new ValidationResult(textView, ValidationResult.Validity.ERROR);
            }
            textView.setError(null);
            return new ValidationResult(textView, ValidationResult.Validity.VALID);
        }
    }
 
Example 4
Project: ElephantAsia   File: StaticTools.java   View Source Code Vote up 5 votes
/**
 * Check if the the textview is empty
 *
 * @param ctx  Current context
 * @param view Le Current TextView
 */
public static void checkEmptyField(Context ctx, TextView view) {
  if (view.getText().toString().trim().length() == 0) {
    view.setError(view.getResources().getString(R.string.empty_field));
  } else {
    view.setError(null);
  }
}
 
Example 5
Project: financisto1-holo   File: Utils.java   View Source Code Vote up 5 votes
public void setTotal(TextView totalText, Total total) {
    if (total.isError()) {
        setTotalError(totalText);
    } else {
        setAmountText(totalText, total);
        totalText.setError(null);
    }
}
 
Example 6
Project: financisto1-holo   File: AbstractTotalsDetailsActivity.java   View Source Code Vote up 5 votes
private void addAmountAndErrorNode(Total total) {
    TextView data = x.addInfoNode(layout, -1, R.string.not_available, "");
    Drawable dr = getResources().getDrawable(R.drawable.total_error);
    dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
    if (total.currency == Currency.EMPTY) {
        data.setText(R.string.currency_make_default_warning);
    } else {
        data.setText(total.getError(AbstractTotalsDetailsActivity.this));
    }
    data.setError("Error!", dr);
}
 
Example 7
Project: data-binding-validator   File: EditTextHandler.java   View Source Code Vote up 5 votes
public static void setError(TextView textView, String errorMessage) {
    TextInputLayout textInputLayout = getTextInputLayout(textView);
    if (textInputLayout != null) {
        textInputLayout.setErrorEnabled(!TextUtils.isEmpty(errorMessage));
        textInputLayout.setError(errorMessage);
    } else {
        textView.setError(errorMessage);
    }
}
 
Example 8
Project: financisto1-holo   File: Utils.java   View Source Code Vote up 4 votes
private void setTotalError(TextView totalText) {
    totalText.setText(R.string.not_available);
    Drawable dr = context.getResources().getDrawable(R.drawable.total_error);
    dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
    totalText.setError(totalText.getText(), dr);
}
 
Example 9
Project: treetracker-android   File: ForgotPasswordFragment.java   View Source Code Vote up 3 votes
public void onClick(View v) {
	
	
	v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
	
	switch (v.getId()) {
		case R.id.fragment_forgot_password_submit:
			
		boolean validForm = true;
		TextView forgotEmail = (TextView) getActivity().findViewById(R.id.fragment_forgot_password_email_address);
		
		if (forgotEmail .getText().length() == 0) {
			forgotEmail.setError("Please enter your e-mail address.");
			forgotEmail.requestFocus();
			validForm  = false;
		} else if (!android.util.Patterns.EMAIL_ADDRESS.matcher(forgotEmail.getText()).matches()) {
			forgotEmail.setError("Please enter valid e-mail address.");
			forgotEmail.requestFocus();
			validForm = false;
		}
		
		
		if (validForm) {
			InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
			inputManager.hideSoftInputFromWindow(forgotEmail.getWindowToken(), 0);

			mResetPassTask = new ResetPasswordTask().execute(new String[]{forgotEmail.getText().toString()});
		}
			
			
		break;

	}
	
}