2016-08-23 86 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);