如何在String []数组中以不同的方式使用“\ n”?

时间:2021-12-01 08:13:32

I have been looking thru some workarounds but nothing seems to work properly using API 15 of Android. I've tried:

我一直在寻找一些解决方法,但似乎没有什么能正常使用Android的API 15。我试过了:

  • System.getProperty("line.separator")
  • "\r\n"

Assuming that I will have a huge array of String (and I want to make it simple):

假设我将拥有一个庞大的String数组(我想让它变得简单):

String[] values = new String[] { "This is a string \n array", 
"This is another \n string array"}; (...)

What's the best way to add a similar solution like

添加类似解决方案的最佳方法是什么?

\n

inside this array?

在这个阵列里面?

2 个解决方案

#1


1  

Use with this \n and in your xml file add this line to the TextView: android:inputType="textMultiLine"

使用此\ n并在您的xml文件中将此行添加到TextView:android:inputType =“textMultiLine”

#2


-2  

you need to escape the new line character in this way "This is another \\n string array" \\ no \n

你需要以这种方式转义新的行字符“这是另一个\\ n字符串数组”\\ no \ n

#1


1  

Use with this \n and in your xml file add this line to the TextView: android:inputType="textMultiLine"

使用此\ n并在您的xml文件中将此行添加到TextView:android:inputType =“textMultiLine”

#2


-2  

you need to escape the new line character in this way "This is another \\n string array" \\ no \n

你需要以这种方式转义新的行字符“这是另一个\\ n字符串数组”\\ no \ n