I'm building an Android app, where I want to read data from a CSV file and display it in some Textviews. The last column can have a larger text with line breaks in it.
Example CSV row that I'm reading to a string array :
Cat1; Cat2; Sample Text\nwith a line break
After setting the string as the text of a textview, I will get this on the device/simulator:
Sample Text\nwith a line break
If I set the string directly like this:
textView.setText("Sample Text\nwith a line break");
Or if I replace a different place holder like this:
( String in CSV: Sample Textzzzwith a line break )
textView.setText(someArray[2].replace("zzz", "\n"));
it will get me the desired result:
Sample Text
with a line break
I also tried .replace("\n", "\n") but this didn't help either.
What am I doing wrong? It's probably something basic.
I'm providing the CSV myself, so I could change something in there as well.
Thanks in advance.
Edit1: Thats how I read the CSV to a string array
int choosenfile = getResources().getIdentifier("test", "raw", getPackageName());
InputStream is = getResources().openRawResource(choosenfile);
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
String line = "";
try{
while ((line = reader.readLine()) != null) {
String[] tokens = line.split(";", -1);
someArray[0] = tokens[0];
someArray[1] = tokens[1];
someArray[2] = tokens[2];
}
} catch (IOException e1) {
Log.e("MainActivity", "Error" + line, e1);
e1.printStackTrace();
}