views:

161

answers:

1

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());
+1  A: 

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(...)

Roflcoptr
Thanks! I can't believe it was that simple. I had the impression that wouldn't work.