0

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?

example

Eclipse
  • 175
  • 1
  • 12
  • 1
    Possible duplicate of [How to remove newlines from beginning and end of a string (Java)?](http://stackoverflow.com/questions/7454330/how-to-remove-newlines-from-beginning-and-end-of-a-string-java) – Mike M. Jul 07 '16 at 00:41

1 Answers1

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