18

I have an Appwidget displaying days until an event like:

eventname (-231 days)

If possible I want to display this String in one line. If the eventname is too long I want to display the full term in braces into a new line. So that it is like:

longeventname
(-231 days)

instead of:

longeventname (-231
days)

(or anything similar)

Is there a way to archive this? Can I make (-231 days) "atomic"?

string.getLength won't work since the size of the widget will vary by device.

Tobias
  • 7,282
  • 6
  • 63
  • 85

1 Answers1

35

You could use a non-breaking space between the number and "days".

That's   for a string in XML, or \u00A0 for a string in Java code.

Martin Stone
  • 12,682
  • 2
  • 39
  • 53
  • Perfect! That ist exactly what I was looking for. "\u00A0" works perfect in Textview. – Tobias Nov 20 '11 at 18:04
  • 10
    For people doing similar things here are two useful hints: First, there is also a non-breaking minus (\u2011) and second you can use a zero width space http://en.wikipedia.org/wiki/Zero-width_space for a possible line break within a word. – Tobias Nov 21 '11 at 10:46
  • 1
    Just a note: It seems that this is working in most cases. However even a non-breaking space will be kinda breaked if preceded by a period (there's no such thing as non-breaking period sadly). So this is not an option if you are working with abbrevations like "P. Howard" – IBoS Sep 04 '12 at 18:40
  • 1
    For people that care about typography, maybe you'd like a [non-breaking hyphen](http://www.fileformat.info/info/unicode/char/2011/index.htm) instead of a minus. – arekolek Jun 09 '17 at 12:41