下面是问题,我有类型的一个例子。我有一个POJO的数据,我需要在一个TextView显示......该数据有假code,它表示每个段落[P]
我想以某种方式解析[P]的成段的时候都显示在TextView中。可以这样做?有什么我可以替代[P],这将使在TextView中一个新的段落?
问问题=新问题();
question.setText(这是第一款[P],这应该是第二个。);
TextView的视图=(TextView中)findViewById(R.id.qtext);
view.setText(question.getParsedText());
解决方案
我会分析整个字符串,然后替换每一个[p]与\ n或甚\ñ\ñ,只要你喜欢。
\ N的字符串做一个换行符。例如使用这样的:
question.setText(这是第一款\ñ\ n和这应该是第二个。);`
这可以做到这一点的方法很容易为String.replace(...)
Below is an example of the type of problem that I have. I have data in a pojo that I need to display in a textview... the data has pseudo code that denotes each paragraph with [p]
I would like to somehow parse the [p]'s into paragraphs when they are displayed in the textview. Can this be done? Is there something I can substitute for the [p] that will make a new paragraph in the 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());
解决方案
Hi i would parse the whole String and then replace every [p] with \n or even \n\n as you like.
\n in the String makes a linebreak. For example use it like that:
question.setText("Here is the first paragraph.\n\n And this should be the second.");`
The method which can do that easily is String.replace(...)