I have an EditText where I put a message in. Let's say I write a message like "Hi" followed by lot of blank lines, then the ChatBubble wraps in the blank lines as well. How can I remove them without converting the Message Object to a String? Is there a way using XML only?
How do I cut blank lines from EditText using XML that the unnecessary lines aren't shown in TextView
Asked
Active
Viewed 990 times
1 Answers
3
You could solve your problem by first taking the text that you enter in the EditText
and save it to a String
variable, like so:
String message = String.valueOf(editText.getText())
Then you could simply replace any new lines (or any text that you are looking for) in that String
variable.
newMessage = message.replace("\n", "")
Replace the "\n" with whatever you want to replace. Using the newMessage
variable, create your ChatBubble
and display the text you want. Hope it helps!

AkashBhave
- 749
- 4
- 12
-
I think a better approach would be using something like `String trimmedString = message.trim();` . Using this you can remove all the whitespaces from the beginning and from the end of a `String`. – Iulian Popescu Jul 07 '16 at 07:26
-
@Iulian Popescu, That is also a good idea, thanks for the help. Either way works. – AkashBhave Jul 08 '16 at 11:26