2012-02-09 249 views
1

我有一個字符串,將被我的下一個類中的intentExtra拾取並設置爲多行TextView的文本。我是wodnering如果分割文本,以便他們下海誓山盟的方式,所以我有這個字符串:分割一個字符串,以便文本在彼此之間

maint = "Here is some info about nothing." + 
       "Some more info about nothing." + 
       "And a little more about nothing"; 

所以通常他們會像這樣顯示在一個TextView:

Here is some info about nothing. Some more info about nothing. And a little more info about nothing. 

是有辦法,這樣他們就結束行之後的那些單獨的件中的每一個被寫入所述的TextView

像這樣:

Here is some info about nothing. 
Some more info about nothing. 
And a little more about nothing. 

它似乎對於每個單獨的句子都有一個單獨的TextView太多了。

在此先感謝

回答

3

添加/ N到你想有一個換行符。

maint = "Here is some info about nothing.\n" + 
     "Some more info about nothing.\n" + 
     "And a little more about nothing"; 

您也可以使用Html格式化它。添加一個你想要換行的地方。

maint = "Here is some info about nothing.</br>" + 
     "Some more info about nothing.</br>" + 
     "And a little more about nothing"; 

如果用HTML格式,你需要把它傳遞給TextView的之前,首先對其進行分析:

myTextView.setText(Html.fromHtml(maint)); 
+0

好甜,謝謝,所以如果我只是使用'\ n'我不必解析? – 2012-02-09 18:52:06

+0

@NickPesa是的,你不需要解析,如果你只是使用'\ n'。爲了供您參考,'\ n'是Java中的換行符。如果你想要更復雜的文本格式,比如不同顏色的文字,你可以使用HTML解析。 – onit 2012-02-09 18:53:37

+0

工作完全謝謝 – 2012-02-09 18:53:56

1

這應該做你想要的(「\ n」是換行符)什麼

maint = "Here is some info about nothing.\n" + 
       "Some more info about nothing.\n" + 
       "And a little more about nothing\n";