RaagaSudha
RaagaSudha

Reputation: 397

How to create multiple lines of text in android?

In my project I need to display the instructions page. The page consists of 8 instructions. So do we need to create 8 textviews to display those instructions? Is it possible to display all those instructions using one single textview?

I read about multi-line textviews.

But for my case can I do so to display all 8 instructions in one textview?

Upvotes: 0

Views: 1994

Answers (4)

Namor Alves
Namor Alves

Reputation: 143

You can use: StringBuilder to it.

Upvotes: 0

Vineet Shukla
Vineet Shukla

Reputation: 24021

You can use \n new line character from string resource or thru code:textView.setText("1st line\n 2nd line");

Upvotes: 2

Rob Pridham
Rob Pridham

Reputation: 4928

As far as I recall, the newline character \n is recognised when used in strings.xml, so you could declare your instructions there and reference it in the layout. I never found a way to do it within the layout XML itself, but there may be something.

Edit: for clarity - I mean using the escaped character, e.g.:

<string name="instructions">Line 1\nLine 2</string>

Upvotes: 3

sebataz
sebataz

Reputation: 1043

You can use html to format your string: textView.setText(Html.fromHtml("item 1<br>item 2<br>"));

Upvotes: 0

Related Questions