Question

I am having a weird problem with the EditText.setError(CharSequence error) method. This is what it is happening to me:

enter image description here

As you can see, the arrow of the message with the information "Let's write a lot to have the problem with the error message!!" is pointing not to the field where the error is, but to the third EditText! (even when there is not even setError method on that EditText).

I have tried to change the error message by doing the same as in here:

EditText setError() with icon but without Popup message

but the result is that I can remove the message text of the EditText, or to change the icon itself, but not to change the message.

Anybody knows how to change this error message to remove that arrow?

Thanks a lot for your help!

Was it helpful?

Solution

I couldn't believe that, but i didn't feel good after reading the source code - they really don't consider such a case for a PopUp in error message.

FYI, See showError() of Editor class and methods used as arguments below:

mErrorPopup.showAsDropDown(mTextView, getErrorX(), getErrorY());
mErrorPopup.fixDirection(mErrorPopup.isAboveAnchor());

Painful reality. I guess the wayout is straightforward: write custom error popUp. However, it's too time consuming for such a minor important UI-part (in most cases). If your TextView is wide enough, I'd just use multilined text. Another option (I didn't try it myself, honestly) is to play with LTR-RTL settings - as souce code shows, the , see the source code:

/**
 * Returns the X offset to make the pointy top of the error point
 * at the middle of the error icon.
 */
private int getErrorX() {
    /*
     * The "25" is the distance between the point and the right edge
     * of the background
     */
    final float scale = mTextView.getResources().getDisplayMetrics().density;

    final Drawables dr = mTextView.mDrawables;

    final int layoutDirection = mTextView.getLayoutDirection();
    int errorX;
    int offset;
    switch (layoutDirection) {
        default:
        case View.LAYOUT_DIRECTION_LTR:
            offset = - (dr != null ? dr.mDrawableSizeRight : 0) / 2 + (int) (25 * scale + 0.5f);
            errorX = mTextView.getWidth() - mErrorPopup.getWidth() -
                    mTextView.getPaddingRight() + offset;
            break;
        case View.LAYOUT_DIRECTION_RTL:
            offset = (dr != null ? dr.mDrawableSizeLeft : 0) / 2 - (int) (25 * scale + 0.5f);
            errorX = mTextView.getPaddingLeft() + offset;
            break;
    }
    return errorX;
}

As you see, the RTL setting doesn't care about TextView width, if you play with it, maybe you'll find the way to set the arrow al the left side.

See also this topic

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top