Skip to content Skip to sidebar Skip to footer

Edittext Ellipsize (three Dots...)

Unfortunatelly I am not able to make ellipsize for EditText works. Is even possible to put three dots at the end of the text when the text is too long? It is working perfectly for

Solution 1:

You have to remove android:inputType attribute.

Ellipsize doesn't work if inputType is defined.

Solution 2:

Set this property to edit text. Elipsize is working with disable edit text

    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:singleLine="true"
    android:editable="false"

Solution 3:

Might not be possible in EditText (unless you create your own View). I think the default behavior (for singleLine EditText) is that you can scroll the text sideways when it can't fit in the view.

Solution 4:

I'm not sure it answers the question (and I guess the original asker is not so interested anymore, after 7 and a half years), but I'm pretty confident my answer will come in handy to anyone stumbling into ellipsis issues with EditText.

Don't try to find any logic in this, but based on the answers from Oleksandr and Mubarak, I figured out the following:

To ellipsize an EditText in XML, use deprecated android:editable="false". In my case:

android:editable="false"android:focusable="false"android:singleLine="true"android:maxLines="1"android:ellipsize="end"

No need to mess with android:inputType="none" for the moment. The EditText looks just like a TextView and is properly ellipsized.

It is possible to make the EditText editable (and remove the ellipsis) like this:

editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setActivated(true);
editText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); // or whatever fits your needs
editText.setSingleLine(true);
editText.setEllipsize(null);
editText.requestFocus();

Your can then restore the EditText to its original state (ie. disguised as a TextView and properly ellipsized) like this:

editText.setFocusable(false);
editText.setFocusableInTouchMode(false);
editText.setActivated(false);
editText.setSingleLine(true);
editText.setKeyListener(null); // this is the key
editText.setEllipsize(TextUtils.TruncateAt.END);

Solution 5:

You need write a new class that extends EditText. for example:

MyEditTextEllipsize extendsEditText{

private String dotsString;

private String storeString;

publicMyEditTextEllipsize(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

@OverrideprotectedvoidonFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);

         if(focused)

     {
       setText(storeString);
      }else {
             StringNOW= getText().toString();
                storeString = NOW;
            if (NOW != null && getWidth() <= getTextSize() * NOW.length()) {

                    dotsString = NOW.substring(0, (int) (getWidth() / getTextSize())) + "...";

                    setText(dotsString);

                }
}

    }
}

Post a Comment for "Edittext Ellipsize (three Dots...)"