Reputation: 43
I have a textview
in the whole layout. I want to know how many characters can be shown on that textview
. I know the width and height of textview
and font size also now I just want to know the number of characters that can show this textview
. I tried textview.getText().toString().length()
but it returns total number of characters which I passed it through the string but it display less.
Upvotes: 3
Views: 1966
Reputation: 36302
While K-ballo's point about fixed-width (and variable-width) fonts is spot on, if you want to know how many characters of a particular string can fit in a TextView
, you might be able to check it using something like Paint.getTextWidths
. Just make sure to set the proper styles/font face before calling it.
Upvotes: 2
Reputation: 8531
So I though there would be a nice solution to this like text.getMaxLength()
But I guess there is not. You'll have to play with some xml that will set the value for you so you know what it is. Check out the sample code in this post
How to Get EditText maxLength setting in code
Upvotes: 1