Android回车内连接字符串

时间:2015-05-27 09:06:50

标签: android textview concatenation carriage-return

请快速提问。

我正在阅读NFC标签并在我的设备屏幕上显示结果,这就是它的显示方式:

The content of the tag is : bla bla bla 

我希望有两行显示为:

The content of the tag is : 

bla bla bla

我添加了

android:singleLine="false"

在TextView定义中,但是现在虽然我有两条线,但它并没有被切割到我想要的位置,因为我得到了这个:

The content of the tag is : bla

bla bla

周围很多人都在谈论\n\r,但我不明白如何将它们整合到我的textView中,因为它是串联的:

 TextView.setText("The content of the tag is :  " + result);

任何提示?干杯

1 个答案:

答案 0 :(得分:1)

尝试

 TextView.setText("Tag is :\n" + result);

或必要时

 TextView.setText("Tag is :\n" + result.replaceAll("[^\\w]+", " "));

它只是用空格替换任何不是字母或数字的字符组。