setEllipsize - Add an ellipsis in a TextView

How to Add an ellipsis in a TextView

setEllipsize added in API Level 1
android:scrollHorizontally added in API Level 1

An ellipsis is three periods in a row. (...)

1. Add a TextView to your activity. 

2. In the main.xml file, add the below line

  <TextView
    ....
       android:text="This is a really, really, really long line of text so you can see how to ellipse works."
   />

3. In the MainActivity.java file, add the following code to the import section. 

          import android.text.TextUtils.TruncateAt;


4. In the MainActivity.java file, add the following code to the onCreate method.

myTextView.setEllipsize(TruncateAt.END);


5. At this point, the ellipsis will not display yet as a TextView is set to automatically expand on default when new text is entered. You will need to limit the TextView in some way. Do do this, you can use either add to your TextView a scrollHorizontally, minLines, or maxLines to have the ellipsis display.  


android:scrollHorizontally = "true"

android:minLines = "2"

android:maxLines = "2"


6. To make the ellipse: 

at the end use:     

              myTextView.setEllipsize(TruncateAt.END);


in the middle use:
              myTextView.setEllipsize(TruncateAt.MIDDLE);

at the start use:
              myTextView.setEllipsize(TruncateAt.START);

to have no ellipse use:
              myTextView.setEllipsize(null);

7. Do not use android:singeLine = "true", it is deprecated.
android:maxLines = "1" will not display the three dots (...)
android:lines = "1" will not display the three dots (...)

8. Compile and run!