Question

I have searched in many threads and could not find the fix .

In the EditText, I have entered a paragraph as below .

"Testing Description (I am pressing the enter key in the keyboard, it is taking me to the next line). This is just for testing "

and when i get the text and print in LogCat using .getText.toString() it is displaying me in the 2 lines . "Testing Description" in one line and it is re-printing the logcat with " This is just for testing"

How to get this in the same string . I get this issue only while pressing the enter key in the keyboard and proceeding the typing .

Actually i want to type a paragraph in the editText and get it in the Single string .

Thanks in Advance .

Was it helpful?

Solution

How to get this in the same string . I get this issue only while pressing the enter key in the keyboard and proceeding the typing .

It always the same string. If you want it on the same line you can try string.replace() to strip away line breaks. For instance

String content = editText.getText.toString();
content = content.replace("\n", "");

OTHER TIPS

When you press enter, there is a special character '\n' enters in your string..It is basically a single string and you just have to remove or replace this character. For this you can use yourString.replace("\n", "");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top