Reputation: 1787
I have a TextView that contains a list of comma seperated phone numbers. i.e. (917) 234-5678, (917) 423-2312 etc
The problem is that the TextView line breaking on spaces so i get something like this:
|(917) 234-5678, (917) 456-8290, (917)|
|423-2313 |
Is there any way to add an "invisible" character that will prevent the TextView from breaking mid-phone number, or alternately some other way of controlling where the line breaks?
UPDATE: One other note, the strings are unknown so I can't just add line breaks in the right place.
Upvotes: 0
Views: 1515
Reputation: 1787
Thanks to @comrade for pointing out the related question. By doing this:
number.replace(" ", "\u00A0")
on each number before concatenating them with commas I was able to get the line break to work as intended.
Upvotes: 1
Reputation: 39836
you could add a line break after every comma. For example:
String phoneNumbers = .... your numbers
phoneNumbers.replace(",", ",\n"); // this adds a line break after all commas
update:
after comment, so maybe you should remove the extra spaces that happen mid-number. Something like:
phoneNumbers.replace(" ", "").replace(",", ", "); // remove all the spaces and re-add one space after the comma, that way auto-line break only happens in-between numbers
The point is that TextView does not have any feature to change the way it breaks lines. So your solution must rely on passing a String to it that it will be more compatible with the way it handles it.
Upvotes: 1
Reputation: 8281
You can do something like yourPhoneText.replace(") ", ")");
Upvotes: 0
Reputation: 894
I think your problem is having a TextView with constant width. Have you tried setting TV width to wrap_content
?
Upvotes: 0