Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TextView: Limit text to specific length with 3 dots

I have TextView which should accept max 6 characters. If value has more than 6, I want to show 3 dots at the end. Used these attributes to achieve that but it just simply cut text at the end without 3 dots.

 android:textAlignment="viewEnd"
 android:maxLines="1"
 android:maxLength="6"
 android:ellipsize="end"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Cleanest and quickest way would be to do so programatically as otherwise you’d need to do hard calculations of the text size + font alongside the TextView’s width

This is the cheapest

textView.text = if(text.length > 6) text.take(6).append("…") else text
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading