Reputation: 2748
I am creating an application that has a data log. I build up this data with a string that I add to everytime the application receives data and then display it in an edittext box.
The problem I am having is that it will display the data but without the new lines.
A basic example of the code:
String logText;
EditText etLog;
logText = data + "\n" + logText;
etLog.setText(logText);
I know that I can use nl = System.getProperty("line.separator");
to get a new line but I'm puzzled as to why "\n" is not working when I've used it in different apps I've created before.
Upvotes: 1
Views: 3789
Reputation: 2748
Not overly keen on answering my own question but I solved it by changing the inputType of my EditText to textMultiLine in my xml code.
xml code:
android:inputType="textMultiLine"
Allows the EditText to make use of "\n" within a string.
Upvotes: 2
Reputation: 379
Usually the problem arises because of a particular programs preferences. The \n
(new line feed) is one possibility, but there is also \r
aka carriage return.
The two are essentially the same, just that there's a standardisation issue. Java uses both for compatibility. Try one, the other, both. Usually one will work.
For editText, I believe its \r\n
.
Upvotes: 1