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

The following examples show how to use android.widget.TextView#setError() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Auxiliar function to get questions 8 to 10 value and set an error if they have not been
 * answered.
 *
 * @param i     Number of question
 * @param id    {@link RatingStars} id
 * @param text  {@link TextView} id of the question title
 * @param error {@link TextView} title of the first question title whose question has an error
 * @return <code>true</code> if an error was set; <code>false</code> otherwise.
 */
private TextView NumberPickerAnswered(int i, int id, int text, TextView error) {
    NumberPicker np = (NumberPicker) findViewById(id);
    int value = np.getValue();
    TextView tv = (TextView) findViewById(text);
    if (value == 0) {
        tv.setError("");
        if (error == null) {
            return tv;
        }
    } else {
        questions[i] = ((i == 7) ? (value - 1) * 10 : (value - 1));
        tv.setError(null);
    }
    return error;
}
 
Example 2
Source Project: financisto   File: Utils.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setTotal(TextView totalText, Total total) {
    if (total.isError()) {
        setTotalError(totalText);
    } else {
        setAmountText(totalText, total);
        totalText.setError(null);
    }
}
 
Example 3
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 4
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 5
Source Project: memoir   File: LinkFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void validate(Dialog dialog, TextView addressView, TextView textView) {
    // retrieve link address and do some cleanup
    final String address = addressView.getText().toString().trim();

    boolean isEmail = sEmailValidator.isValid(address);
    boolean isUrl = sUrlValidator.isValid(address);
    if (requiredFieldValid(addressView) && (isUrl || isEmail)) {
        // valid url or email address

        // encode address
        String newAddress = Helper.encodeQuery(address);

        // add mailto: for email addresses
        if (isEmail && !startsWithMailto(newAddress)) {
            newAddress = "mailto:" + newAddress;
        }

        // use the original address text as link text if the user didn't enter anything
        String linkText = textView.getText().toString();
        if (linkText.length() == 0) {
            linkText = address;
        }

        EventBus.getDefault().post(new LinkEvent(LinkFragment.this, new Link(linkText, newAddress), false));
        try { dialog.dismiss(); } catch (Exception ignore) {}
    } else {
        // invalid address (neither a url nor an email address
        String errorMessage = getString(R.string.rte_invalid_link, address);
        addressView.setError(errorMessage);
    }
}
 
Example 6
/**
 * Auxiliar function to get questions 1 to 6 value and set an error if they have not been
 * answered.
 *
 * @param i      Number of question
 * @param rating {@link RatingStars} id
 * @param text   {@link TextView} id of the question title
 * @param error  {@link TextView} title of the first question title whose question has an error
 * @return <code>true</code> if an error was set; <code>false</code> otherwise.
 */
private TextView RatingStarsAnswered(int i, int rating, int text, TextView error) {
    RatingStars r = (RatingStars) findViewById(rating);
    questions[i] = r.getAnswer();
    TextView tv = (TextView) findViewById(text);
    if (questions[i] == 10) { // default value is 10
        tv.setError("");
        if (error == null) return tv;
    } else {
        tv.setError(null);
    }
    return error;
}
 
Example 7
public static void addError(Context ctx, Object f, TextView label, int strid) {
    if (f instanceof EditText) {
        ((EditText) f).setError(strid == 0 ? null : ctx.getString(strid));
    } else if (f instanceof List && ((List) f).get(0) instanceof EditText) {
        ((List<EditText>) f).get(1).setError(strid == 0 ? null : ctx.getString(strid));
    } else if (label != null) {
        label.setError(strid == 0 ? null : ctx.getString(strid));
    }

}
 
Example 8
static boolean setErrorMessageOnTextView(View inputView, String message){
    if (TextView.class.isAssignableFrom(inputView.getClass())) {
        final TextView text = (TextView) inputView;
        text.setError(message);
        return true;
    } else {
        return false;
    }
}
 
Example 9
Source Project: Android-RTEditor   File: LinkFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void validate(DialogInterface dialog, TextView addressView, TextView textView) {
    // retrieve link address and do some cleanup
    final String address = addressView.getText().toString().trim();

    boolean isEmail = sEmailValidator.isValid(address);
    boolean isUrl = sUrlValidator.isValid(address);
    if (requiredFieldValid(addressView) && (isUrl || isEmail)) {
        // valid url or email address

        // encode address
        String newAddress = Helper.encodeUrl(address);

        // add mailto: for email addresses
        if (isEmail && !startsWithMailto(newAddress)) {
            newAddress = "mailto:" + newAddress;
        }

        // use the original address text as link text if the user didn't enter anything
        String linkText = textView.getText().toString();
        if (linkText.length() == 0) {
            linkText = address;
        }

        EventBus.getDefault().post(new LinkEvent(LinkFragment.this, new Link(linkText, newAddress), false));
        try { dialog.dismiss(); } catch (Exception ignore) {}
    } else {
        // invalid address (neither a url nor an email address
        String errorMessage = getString(R.string.rte_invalid_link, address);
        addressView.setError(errorMessage);
    }
}
 
Example 10
Source Project: openwebnet-android   File: IpcamActivity.java    License: MIT License 5 votes vote down vote up
protected boolean isValidUrl(TextView view) {
    if (view != null && !URLUtil.isValidUrl(editTextIpcamUrl.getText().toString())) {
        view.setError(validationUrl);
        view.requestFocus();
        return false;
    }
    return true;
}
 
Example 11
protected boolean isValidRequired(TextView view) {
    if (utilityService.isBlankText(view)
            || view.getText().equals(labelNone)
            || view.getText().equals(labelMissingGateway)) {
        view.setError(validationRequired);
        view.requestFocus();
        return false;
    }
    return true;
}
 
Example 12
Source Project: financisto   File: Utils.java    License: GNU General Public License v2.0 4 votes vote down vote up
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 13
Source Project: Pioneer   File: ViewUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void setError(TextView view, CharSequence error) {
    view.setError(Texts.withColor(error, Color.RED));
}
 
Example 14
private void showError(int componentId, int stringId) {
	TextView field = (TextView) findViewById(componentId);
	field.setError(getString(stringId));
}
 
Example 15
private void showError(int componentId, int stringId) {
	TextView field = (TextView) findViewById(componentId);
	field.setError(getString(stringId));
}
 
Example 16
Source Project: Pioneer   File: ViewUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void setError(TextView view, CharSequence error) {
    view.setError(Texts.withColor(error, Color.RED));
}
 
Example 17
private boolean validForm() {

        boolean check = true;

        TextView[] fields = new TextView[] {mHost, mUsername, mPassword};

        for (TextView field : fields) {
            if(field.getText().toString().trim().isEmpty()) {
                field.setError(getString(R.string.cannot_be_blank));
                check = false;
            }
        }

        return check;

    }
 
Example 18
private void showError(int componentId, int stringId) {
	TextView field = (TextView) findViewById(componentId);
	field.setError(getString(stringId));
}
 
Example 19
/**
 * Eliminate the error on terms and conditions {@link TextView} if the terms and conditions
 * {@link CheckBox} is clicked.
 *
 * @param view
 * @see TextView#setError(CharSequence)
 */
public void onCheckboxClicked(View view) {
    TextView terms_error = (TextView) findViewById(R.id.terms_text);
    terms_error.setError(null);
}
 
Example 20
/**
 * Eliminate the error on terms and conditions {@link TextView} if the terms and conditions
 * {@link CheckBox} is clicked.
 *
 * @param view
 * @see TextView#setError(CharSequence)
 */
public void onCheckboxClicked(View view) {
    TextView terms_error = (TextView) findViewById(R.id.terms_text);
    terms_error.setError(null);
}