在Android TextView中,是否可以插入段落?

Joh*_*ock 11 android textview

下面是我遇到的问题类型的示例.我有一个pojo中的数据,我需要在textview中显示...数据有伪代码,用[p]表示每个段落

我想以某种方式将[p]解析为文本视图中显示的段落.可以这样做吗?有什么东西我可以替代[p],它会在textview中创建一个新的段落吗?

Question question = new Question();
question.setText("Here is the first paragraph.[p] And this should be the second."); 

TextView view = (TextView) findViewById(R.id.qtext);
view.setText(question.getParsedText());
Run Code Online (Sandbox Code Playgroud)

Rof*_*ion 10

嗨,我将解析整个字符串,然后用\n或甚至\n \n替换每个[p].

字符串中的\n生成一个换行符.例如,使用它:

question.setText("Here is the first paragraph.\n\n And this should be the second.");`
Run Code Online (Sandbox Code Playgroud)

可以轻松完成的方法是String.replace(...)


San*_*gar 5

你也可以试试这个

String summary = "<html><font color=\"#FFFFFF\"" +

             <p align="+ "\"" +"left" + "\""+ ">" +  "MY data" +"</p>"+

                "</font></html>";
mTextView.setText(Html.fromHtml(summary));
Run Code Online (Sandbox Code Playgroud)