Reputation: 3672
I'd like to modify the android TextView
to line-break only at a specified character. For instance, let's say the specified character is +
and the string is as below:
+ Apple + Banana + Coconut + Dragon fruit
The default TextView
behaviour when text overflows.
+ Apple + Banana + Coconut + Dragon
fruit (New line)
Desired behaviour
+ Apple + Banana + Coconut
+ Dragon fruit (New line)
I always struggle with custom views. Any help would be much appreciated.
Upvotes: 2
Views: 619
Reputation: 1
the approach here would be simple just make a method which would be called when the user enters and text in the edittext and then use a simple if block where if the entered character is the same as the one you have decided then just add \n to the text entered. It is the command for new line in java No need of any custom view. Remember always keep things simple while coding
Upvotes: -1
Reputation: 429
You should use an unicode character named NO-BREAK SPACE
: \u00A0
.
Example:
+\u00A0Apple +\u00A0Banana +\u00A0Coconut +\u00A0Dragon\u00A0fruit
This will appear as + Dragon fruit
on UI, but this piece won't be broken in two lines.
Upvotes: 4