Java – Checks if a string is too large to fit in a TextView

Checks if a string is too large to fit in a TextView… here is a solution to the problem.

Checks if a string is too large to fit in a TextView

I have an EditText, a TextView, and a Button. I want to check if the string in EditText is too large or doesn’t fit in the TextView, if not I want to append “..." to the string, so if I write “That’s a nice coat” and it’s too big to fit in the TextView, it will show “That’s a ni…”. I can’t add more rows to the TextView to make it fit.

Solution

Just use maxLines=1 and ellipsize=end in your TextView

If in code, use mText.setEllipsize(TextUtils.TruncateAt.END).

Related Problems and Solutions