2016-08-23 85 views
0

如何在單擊以在文本視圖中顯示數據時在android新活動 中顯示段落數據。 但不使用「HTML」。android佈局中的段落顯示

+0

請閱讀以下文章並根據它調整你的問題http://stackoverflow.com/help/how-to-ask –

回答

0

可以使用實現這一textview

TextView t = findViewById(R.id.text); 

t.setText("This is the first line\nThis is the second line\nThird line..."); 
+1

是它的工作 – Salman

+0

@ onexf,他的答案也有效,但他沒有在textview中設置。 – Vasant

+0

@Salman如果它可以幫助你,請將此標記爲答案。快樂編碼:) – skydroid

0

這是從資源文件中引用一個字符串一個很好的做法(APP->水庫 - >值 - > strings.xml中)。

XML文件保存在res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="paragraph">This is my first big message!\n my second big message.</string> 
</resources> 

這種佈局XML應用將一個字符串查看:

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/paragraph" /> 

如何將字符串檢索:

String string = getString(R.string.paragraph);